2017 © Pedro Peláez
 

library tokenbucket

PHP TokenBucket implementation for rate limit

image

fustundag/tokenbucket

PHP TokenBucket implementation for rate limit

  • Wednesday, September 28, 2016
  • by fustundag
  • Repository
  • 1 Watchers
  • 5 Stars
  • 442 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 1 Open issues
  • 3 Versions
  • 2 % Grown

The README.md

TokenBucket Build Status

TokenBucket is an algorithm for rate limit, (*1)

You can check algorithm from http://en.wikipedia.org/wiki/Token_bucket, (*2)

Usage

Basic usage

``` php <?php, (*3)

use TokenBucket\TokenBucket; use TokenBucket\Storage\Memcached as MemcachedStorage;, (*4)

$storage = new MemcachedStorage();, (*5)

// Define the bucket $options = array( 'capacity' => 20, 'fillRate' => 5 );, (*6)

// Create the bucket $bucket = new TokenBucket('key-for-bucket', $storage, $options);, (*7)

// Check if token is avaible if ($bucket->consume()===false) { //Not allowed!! exit; }, (*8)

// ... ```, (*9)

Options

capacity : Max token count of bucket., (*10)

fillRate : Token count to fill per second. For example if capacity is 20 and fillRate is 5, 5 tokens will added to bucket every second. But, total token cannot be exceed 20., (*11)

ttl : Time to live for bucket in seconds. If not given or zero given, it will be calculated automatically according to capacity and fillRate. ttl can be used to reset bucket with capacity. For example: if capacity is 100 and fillRate is zero and ttl is 300, 100 token can be consumed at 300 seconds. After 300 seconds, bucket will be reset to capacity., (*12)

Rate Limit Http Headers

You can get http headers for rate limit with getRateLimitHttpHeaders method:, (*13)

X-RateLimit-Limit : gives capacity of bucket, (*14)

X-RateLimit-Remaining : allowed token count of bucket, (*15)

X-RateLimit-Reset : time to live of bucket, (*16)

Contributing

You can contribute by forking the repo and creating pull requests. You can also create issues or feature requests., (*17)

License

This project is licensed under the MIT license. LICENSE file can be found in this repository., (*18)

The Versions

28/09 2016

dev-master

9999999-dev http://github.com/fustundag/tokenbucket

PHP TokenBucket implementation for rate limit

  Sources   Download

MIT

The Requires

  • ext-memcached *
  • php >=5.6.0

 

The Development Requires

token rate limit rate limit bucket

28/09 2016

1.0.0

1.0.0.0 http://github.com/fustundag/tokenbucket

PHP TokenBucket implementation for rate limit

  Sources   Download

MIT

The Requires

  • php >=5.6.0
  • ext-memcached *

 

The Development Requires

token rate limit rate limit bucket

25/04 2015

dev-dev

dev-dev http://github.com/fustundag/tokenbucket

PHP TokenBucket implementation for rate limit

  Sources   Download

MIT

The Requires

  • php >=5.3.0
  • ext-memcached *

 

The Development Requires

token rate limit bucket