razonyang/yii2-rate-limiter
最新稳定版本:1.0.0
Composer 安装命令:
composer require razonyang/yii2-rate-limiter
包简介
Yii2 Rate Limiter
关键字:
README 文档
README
Backends
Memcachedrequires memcached extension.Redisrequires redis extension or yiisoft/yii2-redis package.
Installation
composer require razonyang/yii2-rate-limiter
Usage
Let's take 5000 requests every hours as example:
return [ public function behaviors() { return [ // redis via redis extension 'rateLimiter' => [ 'class' => \RazonYang\Yii2\RateLimiter\RedisRateLimiter::class, 'password' => '', 'hostname' => 'localhost', 'port' => 6379, 'capacity' => 5000, 'rate' => 0.72, 'limitPeriod' => 3600, 'prefix' => 'rate_limiter:', 'ttl' => 3600, // 'nameCallback' => $callback, ], // redis via yii2-redis 'rateLimiter' => [ 'class' => \RazonYang\Yii2\RateLimiter\Redis\RateLimiter::class, 'redis' => 'redis', // redis component name or definition 'capacity' => 5000, 'rate' => 0.72, 'limitPeriod' => 3600, 'prefix' => 'rate_limiter:', 'ttl' => 3600, // 'nameCallback' => $callback, ], // memcached 'rateLimiter' => [ 'class' => \RazonYang\Yii2\RateLimiter\MemcachedRateLimiter::class, 'hostname' => 'localhost', 'port' => 11211, 'capacity' => 5000, 'rate' => 0.72, 'limitPeriod' => 3600, 'prefix' => 'rate_limiter:', 'ttl' => 3600, // 'nameCallback' => $callback, ], ]; } ];
RateLimiter takes uid:route(authorized) or ip:route(guest) as bucket name, you can also change this behavior via nameCallback:
$nameCallback = function ( \yii\web\User $user, \yii\web\Request $request, \yii\base\Action $action ): string { return 'bucket name'; }
统计信息
- 总下载量: 24.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2019-08-20