nikolaposa/rate-limit
最新稳定版本:3.2.0
Composer 安装命令:
composer require nikolaposa/rate-limit
包简介
General purpose rate limiter implementation.
关键字:
README 文档
README
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.
统计信息
- 总下载量: 1.45M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 272
- 点击次数: 3
- 依赖项目数: 4
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04