PHP code example of fet / laminas-rate-limiting

1. Go to this page and download the library: Download fet/laminas-rate-limiting library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fet / laminas-rate-limiting example snippets


return [
    // ... other modules ...
    'Fet\\LaminasRateLimiting',
];

return [
    'rate_limiting' => [
        'enabled' => true, // indicates whether rate limiting is enabled
        'max_requests' => 100, // max number of requests
        'window' => 60, // time window in seconds
        'routes' => [ // routes to apply rate limiting (wildcards allowed)
            'home',
            'api/*',
            'admin/*',
        ],
    ],
];

return [
    'rate_limiting' => [
        // ... other config options ...
        'storage' => [
            'options' => [
                'host' => '127.0.0.1',
                'port' => 6379
            ],
        ],
    ],
];

use Acme\Storage\DatabaseStorage;

return [
    'rate_limiting' => [
        // ... other config options ...
        'storage' => [
            'name' => DatabaseStorage::class, // this will be loaded via service manager
            'options' => [],
        ],
    ],
];