PHP code example of atakde / php-rate-limiter
1. Go to this page and download the library: Download atakde/php-rate-limiter 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/ */
atakde / php-rate-limiter example snippets
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$storage = new RedisStorage($redis);
// Allow maximum 10 requests in 60 seconds.
$rateLimitter = new RateLimiter([
'refillPeriod' => 60,
'maxCapacity' => 10,
'prefix' => 'api'
], $storage);
$ip = $_SERVER['REMOTE_ADDR'];
if ($rateLimitter->check($ip)) {
echo 'OK';
} else {
echo 'Limit Exceeded';
}
bash
composer