1. Go to this page and download the library: Download bayfrontmedia/leaky-bucket library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bayfrontmedia / leaky-bucket example snippets
use Bayfront\LeakyBucket\Adapters\Flysystem;
$adapter = new Flysystem($filesystem, '/root_path');
use Bayfront\LeakyBucket\Adapters\Local;
$adapter = new Local('/root_path');
use Bayfront\LeakyBucket\Adapters\PDO;
$adapter = new PDO($dbh, 'table_to_use');
use Bayfront\LeakyBucket\AdapterException;
use Bayfront\LeakyBucket\BucketException;
use Bayfront\LeakyBucket\Bucket;
// Create/retrieve a bucket with a given ID
try {
$bucket = new Bucket('bucket_id', $adapter, [
'capacity' => 10, // Total drop capacity
'leak' => 10 // Number of drops to leak per minute
]);
} catch (AdapterException | BucketException $e) {
die($e->getMessage());
}
// Work with the bucket
$bucket->leak();
if ($bucket->hasCapacity()) {
try {
$bucket->fill()->save();
} catch (AdapterException $e) {
die($e->getMessage());
}
}