highweb / yii2-ip-ratelimiter
允许访客客户端被速率限制,使用它们的IP地址作为标识符。
1.1.3
2017-03-16 15:42 UTC
README
yii2-ip-ratelimiter
允许访客客户端被速率限制,使用它们的IP地址作为标识符。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令:
php composer.phar require highweb/yii2-ip-ratelimiter "^1.0"
或者在您的 composer.json
文件的 require 部分添加:
"highweb/yii2-ip-ratelimiter": "^1.0"
使用方法
修改您想进行速率限制的控制器的行为方法
public function behaviors() { return [ 'rateLimiter' => [ // Use class 'class' => \highweb\ratelimiter\RateLimiter::className(), // The maximum number of allowed requests 'rateLimit' => 100, // The time period for the rates to apply to 'timePeriod' => 600, // Separate rate limiting for guests and authenticated users // Defaults to true // - false: use one set of rates, whether you are authenticated or not // - true: use separate ratesfor guests and authenticated users 'separateRates' => false, // Whether to return HTTP headers containing the current rate limiting information 'enableRateLimitHeaders' => false, ] ]; }
由 ethercreative/yii2-ip-ratelimiter 分支而来。