silencenjoyer / rate-limiter
A rate limiter to control and manage execution flow.
3.0.0
2025-07-09 21:14 UTC
Requires
- php: ^7.4|^8.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2025-07-09 21:16:54 UTC
README
This package provides possibility to control and manage execution flow.
Installation
You can install the package via composer:
composer require silencenjoyer/rate-limiter
Usage
use Silencenjoyer\RateLimit\Counters\LocalCounter; use Silencenjoyer\RateLimit\Intervals\Interval; use Silencenjoyer\RateLimit\Limiters\RateLimiter; use Silencenjoyer\RateLimit\Rates\Rate; require_once __DIR__ . '/vendor/autoload.php'; $counter = new LocalCounter(); $rateLimiter = new RateLimiter($counter, new Rate(5, new Interval('PT1S'))); if (!$rateLimiter->isExceed()) { $rateLimiter->collectUsage(); // do some logic } throw new RuntimeException('Rate limit has been exceeded.');
Testing
composer test
composer test-coverage
docker-compose -f tests/docker/docker-compose.test.yml up
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email an_gebrich@outlook.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.