A PHP package for rate limiting.
Install via composer
composer require atakde/php-rate-limiter
$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';
}