php-ratelimiter
php-ratelimiter copied to clipboard
Call the rate limiter many times in the same php code with different limits
With this branch we can do this:
$memcache = new Memcache;
$memcache->connect('127.0.0.1',11211);
$rateLimiter = new RateLimiter($memcache, $_SERVER["REMOTE_ADDR"]);
try {
// 10 requests / minute
$rateLimiter->limitRequestsInMinutes(10, 1);
} catch (RateExceededException $e) {
header("HTTP/1.0 529 Too Many Requests");
exit;
}
try {
// 30 requests / 5 minute
$rateLimiter->limitRequestsInMinutes(30, 5);
} catch (RateExceededException $e) {
header("HTTP/1.0 529 Too Many Requests");
exit;
}
etc....