Need help with rate-limit?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

nikolaposa
195 Stars 26 Forks MIT License 159 Commits 3 Opened issues

Description

🚔 General purpose rate limiter implementation.

Services available

!
?

Need anything else?

Contributors list

# 271,951
PHP
C++
Redis
rate-li...
116 commits
# 49,663
PHP
slim-fr...
Symfony
oauth2
9 commits
# 7,665
Compose...
PHP
PHPUnit
Nette
8 commits
# 102,805
CSS
Redis
PHP
rate-li...
2 commits
# 207,568
Symfony
PHP
HTML
Shell
1 commit
# 383,752
HTML
Redis
PHP
rate-li...
1 commit

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 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(); //99

Supported drivers

Credits

License

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.