定制 kelunik/rate-limit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kelunik/rate-limit

最新稳定版本:v3.0.0

Composer 安装命令:

composer require kelunik/rate-limit

包简介

Rate Limiting for Amp.

README 文档

README

License

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

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-04-10