Skip to content
PHP Rate Limiting Library With Token Bucket Algorithm
Branch: master
Clone or download
Latest commit a68b6bb Oct 31, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.codeclimate.yml
.gitignore
.travis.yml
README.md
composer.json

README.md

Build Status Code Climate

RateLimit

PHP Rate Limiting Library With Token Bucket Algorithm

Storage Adapters

Example

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

$id = $_SERVER['REMOTE_ADDR']; // Use client IP as identity
if ($rateLimit->check($id) > 0) {
  echo "passed";
} else {
  echo "rate limit exceeded";
}

Installing via Composer

curl -sS https://getcomposer.org/installer | php
composer.phar require touhonoob/rate-limit

References

You can’t perform that action at this time.