Skip to content

atakde/php-rate-limiter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-rate-limiter

A PHP package for rate limiting.

Installation

Install via composer

composer require atakde/php-rate-limiter

Usage

$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$storage = new RedisStorage($redis);

// Allow maximum 10 requests in 60 seconds.
$rateLimitter = new RateLimiter([
    'refillPeriod' => 60,
    'maxCapacity' => 10,
    'prefix' => 'api'
], $storage);

$ip = $_SERVER['REMOTE_ADDR'];
if ($rateLimitter->check($ip)) {
    echo 'OK';
} else {
    echo 'Limit Exceeded';
}

About

PHP Rate Limiter (Token Bucket Algorithm)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages