kelunik/rate-limit
最新稳定版本:v3.0.0
Composer 安装命令:
composer require kelunik/rate-limit
包简介
Rate Limiting for Amp.
README 文档
README
kelunik/rate-limit is a rate limiting library for Amp.
Installation
composer require kelunik/rate-limit
Usage
You're in full control of any actions when the rate limit is exceeded. You can also already warn the user before he exceeds the limit.
$current = $this->rateLimit->increment("{$userId}:{$action}"); if ($current > $this->limit) { // show captcha or error page or do anything you want } else { // request is within the limit, continue normally }
If you want to expose the limits, e.g. in an HTTP API, you can also request the reset time for a given key.
$current = $this->rateLimit->increment("{$userId}:{$action}"); $response->setHeader("x-ratelimit-limit", $this->limit); $response->setHeader("x-ratelimit-remaining", $this->limit - $current); $response->setHeader("x-ratelimit-reset", $this->rateLimit->getTtl("{$userId}:{$action}"));
RateLimit::getTtl() returns the seconds until the limit is reset. If you want to return the absolute time, you can just add time() to that value.
统计信息
- 总下载量: 156
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 13
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-10