cschalenborgh / laravel-rate-limiter
Laravel的速率限制器
1.0.3
2020-04-17 15:44 UTC
Requires
- php: >=7.1
- illuminate/cache: ~5.8.0 || ^6.0 || ^7.0
- illuminate/config: ~5.8.0 || ^6.0 || ^7.0
- illuminate/container: ~5.8.0 || ^6.0 || ^7.0
- illuminate/support: ~5.8.0 || ^6.0 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-18 02:11:38 UTC
README
描述
您可以使用此包轻松地在Laravel应用程序中对特定逻辑进行速率限制,从Guzzle请求到更具体的应用程序逻辑。此包基于 https://github.com/touhonoob/RateLimit。
安装
您可以通过composer安装此包
composer require cschalenborgh/laravel-rate-limiter
服务提供者将自动注册。或者您可以在config/app.php文件中手动添加服务提供者
'providers' => [ // ... Cschalenborgh\RateLimiter\RateLimiterServiceProvider::class, ];
使用方法
use Cschalenborgh\RateLimiter\RateLimiter; $rate_limiter = new RateLimiter('action_name', 5, 60); // max 5 times in 60 seconds if ($rate_limiter->check($lock_identifier)) { // perform some action } else { // oops.. limit reached }