This is yet another Throttling library for PHP applications, that provides a throttling interface and a flexible API for implementing custom throttling algorithms (aka providers) and storage strategies.
$ composer require tiendanube/throttler
<?php
$storage = new TiendaNube\Throttler\Storage\InMemory();
$provider = new TiendaNube\Throttler\Provider\LeakyBucket();
$throttler = new \TiendaNube\Throttler\Throttler($provider,$storage);
if (!$throttler->throttle('client:1')) {
// allow
} else {
// deny
}
Currently, the only available provider is the Leaky Bucket algorithm.
If you need a different algorithm for throttling, just create your own class and implement the ProviderInterface.
Currently, the only available storage strategy is the InMemory adapter, that stores the information in memory, that is useful for CLI applications.
If you want to implement a custom storage (for example, a Redis database), just create your own class and implement the StorageInterface.
Feel free to contribute with bug fixing, new providers and storage strategies.
To start contributing, just make a fork of this repo, create a branch which the name explains what you are doing, code your solution and send us a Pull Request.
$ composer install --dev
$ ./vendor/bin/phpunit
Coming soon.
This library is licensed under the MIT license.