PHP code example of fustundag / tokenbucket

1. Go to this page and download the library: Download fustundag/tokenbucket 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/ */

    

fustundag / tokenbucket example snippets

 php


use TokenBucket\TokenBucket;
use TokenBucket\Storage\Memcached as MemcachedStorage;

$storage = new MemcachedStorage();

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

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

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

// ...