sndsgd/rate
Composer 安装命令:
composer require sndsgd/rate
包简介
Rate limiting for PHP
README 文档
README
Rate limiting for PHP.
Requirements
This project is unstable and subject to changes from release to release.
You need PHP >= 7.0 to use this library, however, the latest stable version of PHP is recommended.
Install
Install sndsgd/rate using Composer.
Usage
Note: At the moment, this library only contains rate limiting tools.
# define the rate limits $clientIp = $di->getClient()->getIp(); $limits = [ new \sndsgd\rate\Limit("Search-PerSecond", $clientIp, 1, 3), new \sndsgd\rate\Limit("Search-PerHour", $clientIp, 600, 3600), ]; # create a limiter, and increment the hit counts for all limits $redis = $di->getRedis(); $limiter = new \sndsgd\rate\limiter\RedisLimiter($redis, $limits); $limiter->increment(); # copy the rate limit headers to the response $response = $di->getResponse(); foreach ($limiter->getHeaders() as $header) { list($key, $value) = preg_split("/\:\s?/", $header, 2); $response->addHeader($key, $value); } # if the limit was exceeded, prevent futher execution if ($limiter->isExceeded()) { throw new \sndsgd\http\exception\TooManyRequestsException(); }
统计信息
- 总下载量: 363
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-30