zeus / throttle
PHP节流库包
1.0.0
2020-11-06 12:34 UTC
Requires
- php: >=7.4
- predis/predis: ^1.1
This package is auto-updated.
Last update: 2024-09-09 03:20:11 UTC
README
带Redis的PHP速率限制库
使用Composer安装
composer require zeus/throttle
设置HTTP请求限制,例如10分钟内只允许100次访问。强大的Redis处理HTTP请求,您可以轻松将其集成到所有API或项目中
use Throttle\Throttle; use Throttle\Time; $throttle = new Throttle( new Time(60, 25) ); $throttle->commit(); if ($throttle->isHasAccessLimit()) { print 'request can go next'; } else { print 'max request amount'; }
如果您想配置Redis客户端
use Throttle\Throttle; use Throttle\Time; use Throttle\Redis; Redis::setRedisClient(new \Predis\Client($params)); $throttle = new Throttle( new Time(60, 25) ); $throttle->commit(); if ($throttle->isHasAccessLimit()) { print 'request can go next'; } else { print 'max request amount'; }
获取详细信息
$throttle->getDetail()->toArray();