perimeter/rate-limiter-php
最新稳定版本:v0.1.1
Composer 安装命令:
composer require perimeter/rate-limiter-php
包简介
A very simple Rate Limiter for PHP
README 文档
README
Rate Limit those APIs!
Installation
$ composer.phar require perimeter/rate-limiter-php:dev-develop
This library can be used alongside the perimeter/RateLimitBundle for Symfony2 applications. See the repository for more instructions.
Get Started
Create your throttler:
include_once('vendor/autoload.php'); $redis = new Predis\Client(); $throttler = new Perimeter\RateLimiter\Throttler\RedisThrottler($redis);
Ensure redis is running by executing the redis-server command on the web server where
the library is running:
$ redis-server
Now you can throttle your users accordingly!
// Create a meter ID based on something unique to your user // In this case we use the IP. This can also be a username, // company, or some other authenticated property $meterId = sprintf('ip_address:%s', $_SERVER['REMOTE_ADDR']); $warnThreshold = 10; $limitThreshold = 20; // run the "consume" command $throttler->consume($meterId, $warnThreshold, $limitThreshold); if ($throttler->isLimitWarning()) { echo "slow down!"; } if ($throttler->isLimitExceeded()) { exit("you have been rate limited"); }
And that's it!
统计信息
- 总下载量: 15.27k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 17
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-26