2017 © Pedro Peláez
 

library rate-limit

Rate Limiting Library With Token Bucket Algorithm

image

touhonoob/rate-limit

Rate Limiting Library With Token Bucket Algorithm

  • Tuesday, October 31, 2017
  • by touhonoob
  • Repository
  • 4 Watchers
  • 61 Stars
  • 14,300 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 10 Forks
  • 1 Open issues
  • 6 Versions
  • 31 % Grown

The README.md

RateLimit

Build Status, (*1)

PHP Rate Limiting Library With Token Bucket Algorithm with minimal external dependencies., (*2)

Installation

composer require palepurple/rate-limit, (*3)

Storage Adapters

The RateLimiter needs to know where to get/set data., (*4)

Depending on which adapter you install, you may need to install additional libraries (predis/predis or tedivm/stash) or PHP extensions (e.g. Redis, Memcache, APC), (*5)

Example

require 'vendor/autoload.php';

use \PalePurple\RateLimit\RateLimit;
use \PalePurple\RateLimit\Adapter\APC as APCAdapter;
use \PalePurple\RateLimit\Adapter\Redis as RedisAdapter;
use \PalePurple\RateLimit\Adapter\Predis as PredisAdapter;
use \PalePurple\RateLimit\Adapter\Memcached as MemcachedAdapter;
use \PalePurple\RateLimit\Adapter\Stash as StashAdapter;


$adapter = new APCAdapter(); // Use APC as Storage
// Alternatives:
//
// $adapter = new RedisAdapter((new \Redis()->connect('localhost'))); // Use Redis as Storage
//
// $adapter = new PredisAdapter((new \Predis\Predis())->connect('localhost')); // Use Predis as Storage
//
// $memcache = new \Memcached();
// $memcache->addServer('localhost', 11211);
// $adapter = new MemcacheAdapter($memcache); 
//
// $stash = new \Stash\Pool(new \Stash\Driver\FileSystem());
// $adapter = new StashAdapter($stash);

$rateLimit = new RateLimit("myratelimit", 100, 3600, $adapter); // 100 Requests / Hour

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

Installing via Composer

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

References

The Versions

31/10 2017

dev-master

9999999-dev

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar touhonoob

14/11 2016

dev-redis-custom-client

dev-redis-custom-client

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar touhonoob

07/06 2016

1.2.0

1.2.0.0

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar touhonoob

06/06 2016

dev-php7-apcu

dev-php7-apcu

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Avatar touhonoob

23/05 2015

1.1.0

1.1.0.0

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • ext-apc ^4.0

 

The Development Requires

by Avatar touhonoob

16/05 2015

1.0.0

1.0.0.0

Rate Limiting Library With Token Bucket Algorithm

  Sources   Download

MIT

The Requires

  • ext-apc ^4.0

 

The Development Requires

by Avatar touhonoob