PHP Rate Limiting Library With Token Bucket Algorithm
PHP Rate Limiting Library With Token Bucket Algorithm
require 'vendor/autoload.php';
use \Touhonoob\RateLimit\RateLimit;
use \Touhonoob\RateLimit\Adapter\APC as RateLimitAdapterAPC;
use \Touhonoob\RateLimit\Adapter\Redis as RateLimitAdapterRedis;
$adapter = new RateLimitAdapterAPC(); // Use APC as Storage
// $adapter = new RateLimitAdapterRedis(); // Use Redis as Storage
$rateLimit = new RateLimit("myratelimit", 100, 3600, $adapter); // 100 Requests / Hour
$ip = $_SERVER['REMOTE_ADDR'];
if ($rateLimit->check($ip) > 0) {
echo "passed";
} else {
echo "rate limit exceeded";
}
curl -sS https://getcomposer.org/installer | php
composer.phar require touhonoob/rate-limit