PHP code example of coon-design / rate-limit

1. Go to this page and download the library: Download coon-design/rate-limit 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/ */

    

coon-design / rate-limit example snippets


$rateLimitMiddleware = new \Prezto\RateLimit\RateLimitMiddleware('10.241.25.226', '6379', 'aslkjkrnflawekrmgfslerm')

$rateLimitMiddleware->setRequestsPerSecond(60, 30);

$rateLimitMiddleware->useMemcache();

$rateLimitMiddleware->setHandler(function ($request, $response) {
            $response = $response->withStatus(429);
            $response->getBody()->write("Rate limit reached.");
            return $response;
        });