hi-man/rateguardian
Composer 安装命令:
composer require hi-man/rateguardian
包简介
local rate limit based on yac
README 文档
README
keep your server calm down
Requirements
- php 7.3+
- yac 2.0.3+
Installation
composer require hi-man/rateguardian
Usage
step 1 : initialize guardian
RateGuardian::getInstance()->guardianOn($key, $total, $ttl)
$keythe unique guardian key, such as api pathname, not longer than 41 characters$ttlin seconds, a counter will be increased in this period$totalthe max counter value allowd in$ttlsecond
step 2 : guard api with guardian key
RateGuardian::getInstance()->guard($key);
- a
falsevalue indicates the api is overloaded, application should handle this situation instead of providing service - return value
- return
trueif counter less than$total - return
trueif counter equals$total - return
trueif$keydoes not be registered withguardianOn - otherwise return
false
- return
step 3 : clear guardian
RateGuardian::getInstance()->guardianOff($key);
- restart
php-fpmor php script also cleared guardian setting
optional: get guardian info
RateGuardian::getInstance()->show($key);
- return a array of guardian info
totalthe value provided byguardianOnttlthe value provided byguardianOnexpiredunix timestamp that calculating periods endedcurrentcurrent counter value
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-29