uz/yii2-ip-ratelimiter

允许以IP作为标识符,对访客客户端进行限速。

安装: 16

依赖: 0

建议者: 0

安全: 0

星级: 2

关注者: 2

分支: 0

开放问题: 0

类型:yii2-module

1.0.2 2016-11-25 17:14 UTC

This package is not auto-updated.

Last update: 2024-09-23 13:52:28 UTC


README

Yii2 IP Rate Limiter

yii2-ip-ratelimiter

允许以IP作为标识符,对访客客户端进行限速。

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一

php composer.phar require uz/yii2-ip-ratelimiter "^1.0"

或将以下内容添加到您的 composer.json 文件的 require 部分。

"uz/yii2-ip-ratelimiter": "^1.0"

使用方法

修改您想进行限速的控制器的 behavior 方法

public function behaviors()
{
	$behaviors = parent::behaviors();
	$behaviors['rateLimiter'] = [
		// Use class
		'class' => \Mronx\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,
	];
	return $behaviors;
}

ethercreative/yii2-ip-ratelimiter 分支而来