PHP code example of codeages / token-bucket
1. Go to this page and download the library: Download codeages/token-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/ */
codeages / token-bucket example snippets
$tokens = 30; //the bucket capacity
$rates = 10; //recover tokens per second
$consume = 10; //consume tokens
$key = "test"; //bucket name
$redis = new \Redis();
$redis->connect('127.0.0.1', 6379, 1);
$driver = new RedisDriver("test", $redis);
$tokenBucket = new TokenBucket($tokens, $rates, $name);
$tokenBucket->setDriver($driver)->watch();
$tokenBucket->consume($consume);