PHP MIT

rate-limit

🚔 General purpose rate limiter implementation.

N

nikolaposa

Dernière activité 24 juin 2026
nikolaposa/rate-limit

276

étoiles

48

forks

7

issues ouvertes

rate-limitrate-limitingredis

Ce README est souvent en anglais.

Rate Limit

Build Scrutinizer Code Quality Code Coverage Latest Stable Version PDS Skeleton

General purpose rate limiter that can be used to limit the rate at which certain operation can be performed. Default implementation uses Redis as backend.

Installation

The preferred method of installation is via Composer. Run the following command to install the latest version of a package and add it to your project's composer.json:

composer require nikolaposa/rate-limit

Usage

Terminating rate limiter

use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$apiKey = 'abc123';

try {
    $rateLimiter->limit($apiKey);
    
    //on success
} catch (LimitExceeded $exception) {
   //on limit exceeded
}

Silent rate limiter

use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;

$rateLimiter = new RedisRateLimiter(Rate::perMinute(100), new Redis());

$ipAddress = '192.168.1.2';
$status = $rateLimiter->limitSilently($ipAddress);

echo $status->getRemainingAttempts(); //99

Practical usage with configuring multiple rate limiting strategies in a project

use RateLimit\Rate;
use RateLimit\RedisRateLimiter;

$container->set('rate_limiter.api', new RedisRateLimiter(Rate::perSecond(10), $container->get('redis')));
$container->set('rate_limiter.videos', new RedisRateLimiter(Rate::perDay(5), $container->get('redis')));

Supported drivers

Credits

License

Released under MIT License - see the License File for details.

Projets similaires

Rate limiting for go-redis

Gogcraleaky-bucketrate-limiting
Ggo-redis
1,1 k étoiles107

Rate Limiting extension for Flask

Pythonflaskmemcachedpython
Aalisaifee
1,2 k étoiles130

⚔️Python Rate-Limiter using Leaky-Bucket Algorithm Family

Pythonleaky-bucketpythonrate-limit
Vvutran1710
525 étoiles52