arash/rlr
最新稳定版本:v0.1.0
Composer 安装命令:
composer require arash/rlr
包简介
rate limit request
README 文档
README
Requirement
- minimum php 5.4
- redis
- memcached
- For connect to Redis define and set
REDIS_HOSTandREDIS_PORTenvironment variable. Default value for host is127.0.0.1and port is6379. - For connect to Memcached define and set
MEMCACHED_HOSTandMEMCACHED_PORTenvironment variable. Default value for host is127.0.0.1and port is11211.
Installation
- with composer:
composer require arash/rlr - manually:
- yii:
- copy this package to the desired directory
- set blow config in
aliasessection'@arash/rlr' => __DIR__ . 'pathToDirectory/rlr/src',
- laravel:
- copy this package to
app/Services - add
"arash\\rlr\\": "app/Services/rlr/src"inpsr-4ofautoloadsection - run
composer dumpautoload
- copy this package to
- yii:
Usage
use RLRService before the request arrive to action.
use arash\rlr\RLRService; //default handler is memcache $limiter = new RLRService(RLRService::HANDLER_REDIS); //default is 10 request per 60 seconds. //count of request per window $limiter->handler->limit = 5; //time window $limiter->handler->window = 60; //list of IPs that you want banned $limiter->handler->banList = []; if ($limiter->handler->isRateLimited()) { echo 'Rate limit exceeded. Please try again later.'; } else { echo 'Request successful.'; }
Yii
Copy RLRFilter.php in app\components directory and add blow code in behavior of your component.
$behaviors['rlr'] = [ 'class' => 'app\components\RLRFilter', 'only' => ['array of actions'], 'except' => ['array of actions'], 'handlerClass' => RLRService::HANDLER_REDIS, //default handler is memcache 'limit' => 3, //count of request per window 'window' => 15, //time window 'message' => 'your message', 'banList' => 'list of IPs in array or string that separate with comma' ];
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2024-08-27