2017 © Pedro Peláez
 

library leakybucket

An implementation of the Leaky Bucket algorithm.

image

cr0nixx/leakybucket

An implementation of the Leaky Bucket algorithm.

  • Tuesday, March 21, 2017
  • by Cr0nixx
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

LeakyBucket Build Status

Leaky Bucket is an algorithm which works as follows:, (*1)

  1. There is a bucket.
  2. The bucket has a defined leak and defined capacity.
  3. The bucket leaks at a constant rate.
  4. Overflows when full, will not add other drops to the bucket.

Install

php composer.phar require "pskuza/leakybucket", (*2)

Usage

Basic usage

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

use LeakyBucket\LeakyBucket; use LeakyBucket\Storage\RedisStorage;, (*4)

// Define which storage to use $storage = new RedisStorage();, (*5)

// Define the bucket $settings = [ 'capacity' => 10, 'leak' => 1 ];, (*6)

// Create the bucket $bucket = new LeakyBucket('example-bucket', $storage, $settings);, (*7)

// Fill the bucket $bucket->fill(); $bucket->save();, (*8)

// Check if it's full if ($bucket->isFull()) { header('HTTP/1.1 429 Too Many Requests'); die(', (*9)

429 Too Many Requests

You seem to be doing a lot of requests. You\'re now cooling down., (*10)

'); }, (*11)

// ..., (*12)


### For memcached use ``` php <?php use LeakyBucket\LeakyBucket; use LeakyBucket\Storage\MemcachedStorage; // Define which storage to use $storage = new MemcachedStorage();

Other functionality

You can also do great stuff with it through the methods that LeakyBucket provides., (*13)

``` php // Get capacity information $capacityTotal = $bucket->getCapacity(); $capacityLeft = $bucket->getCapacityLeft(); $capacityUsed = $bucket->getCapacityUsed();, (*14)

// Get the drops/second that the bucket leaks $leakPerSecond = $bucket->getLeak();, (*15)

// Get the last timestamp from when the bucket was updated $timestamp = $bucket->getLastTimestamp();, (*16)

// Set additional data $bucket->setData( [ 'timeout' => 3600 ] );, (*17)

// Set additional data $data = $bucket->getData();, (*18)

// Update the bucket with the leaked drops $bucket->leak();, (*19)

// Remove excess drops $bucket->overflow();, (*20)

// Update the bucket's timestamp manually $bucket->touch();, (*21)

// Fill the bucket with one drop $bucket->fill();, (*22)

// Fill the bucket with 5 drops $bucket->fill(5);, (*23)

// Spill one drop from the bucket $bucket->spill();, (*24)

// Spill 5 drops from the bucket $bucket->spill(5);, (*25)

// Remove the bucket's content $bucket->reset();, (*26)

// Force save $bucket->save(); ```, (*27)

Contributing

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

Checklist

  1. Your code complies with the PSR-2 standards. (check using the php-cs-checker)
  2. Your code is fully tested and PHPUnit tests are also supplied.
  3. Your code passes in TravisCI build.
  4. By contributing your code, you agree to license your contribution under the MIT license.

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

The Versions

21/03 2017

dev-master

9999999-dev

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Jeroen Visser
by Philip Skuza

firewall throttling limits leakybucket

21/03 2017

0.2

0.2.0.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

by Jeroen Visser
by Philip Skuza

firewall throttling limits leakybucket

17/01 2015

0.1.4

0.1.4.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jeroen Visser

firewall throttling limits leakybucket

06/07 2014

0.1.3

0.1.3.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jeroen Visser

firewall throttling limits leakybucket

06/07 2014

0.1.2

0.1.2.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jeroen Visser

firewall throttling limits leakybucket

05/07 2014

0.1.1

0.1.1.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jeroen Visser

firewall throttling limits leakybucket

05/07 2014

0.1.0

0.1.0.0

An implementation of the Leaky Bucket algorithm.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jeroen Visser

firewall throttling limits leakybucket