hao / algorithm
api接口限流
1.0.2
2020-09-16 07:39 UTC
Requires
- php: >=5.3.3
This package is auto-updated.
Last update: 2025-03-16 17:38:13 UTC
README
接口限流
开源地址
https://github.com/JZhao1020/algorithm
##1.安装
composer require hao/algorithm
##2.实例化
$config = [
'limit' => 10, // 请求限制量
'interval' => 2000, // 请求单位时间 毫秒
];
$Counter = new \limiting\Algorithm($config);
##2.1 计数器限流
$url = 'limiting:counter:'. url();
$Counter->gateway('Counter')->slidingGrant($url);
##2.2 令牌限流
$url = 'limiting:token_bucket:'. url();
$Counter->gateway('TokenBucket')->slidingGrant($url);