PHP code example of nadylib / leaky-bucket

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

    

nadylib / leaky-bucket example snippets


use Nadylib\LeakyBucket\LeakyBucket;

$bucket = new Nadylib\LeakyBucket\LeakyBucket(
	size: 5,
	refillDelay: 1.0,
	refillAmount: 1
);

use Nadylib\LeakyBucket\LeakyBucket;

$bucket = new Nadylib\LeakyBucket\LeakyBucket(
	size: 5,
	refillDelay: 1.0,
	refillAmount: 1
);
for ($i = 1; $i <= 7; $i++) {
	$bucket->take(1);
	$time = (new DateTimeImmutable())->format("H:i:s.v");
	echo("[{$time}] Taken.\n");
}

use Nadylib\LeakyBucket\LeakyBucket;
use Revolt\EventLoop;

$bucket = new Nadylib\LeakyBucket\LeakyBucket(
	size: 5,
	refillDelay: 1.0,
	refillAmount: 1
);
for ($i = 1; $i <= 7; $i++) {
	$bucket->take(callback: function() {
		$time = (new DateTimeImmutable())->format("H:i:s.v");
		echo("[{$time}] Taken.\n");
	});
}
EventLoop::run();