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.
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-limitOffensive rate limiting
use RateLimit\Exception\LimitExceeded;
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;
$rateLimiter = new RedisRateLimiter(new Redis());
$apiKey = 'abc123';
try {
$rateLimiter->limit($apiKey, Rate::perMinute(100));
//on success
} catch (LimitExceeded $exception) {
//on limit exceeded
}Silent rate limiting
use RateLimit\Rate;
use RateLimit\RedisRateLimiter;
use Redis;
$rateLimiter = new RedisRateLimiter(new Redis());
$ipAddress = '192.168.1.2';
$status = $rateLimiter->limitSilently($ipAddress, Rate::perMinute(100));
echo $status->getRemainingAttempts(); //99Released under MIT License - see the License File for details.

