1. Go to this page and download the library: Download karmabunny/rdb 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/ */
// Wait for a lock for up to 10 seconds.
$lock = $rdb->lock('locks:key', 10 * 1000);
if ($lock === null) {
echo "Busy - too much contention\n";
}
else {
// Do atomic things.
$lock->release();
}
// A bucket with 60 drips per minute.
$bucket = $rdb->getBucket([
'key' => 'key',
// Defaults.
'capacity' => 60,
'drip_rate' => 1,
// Optional.
'prefix' => 'drips:',
'costs' => [
'GET' => 1,
'POST' => 10,
],
]);
// One drip.
$full = $bucket->drip();
if ($full) {
echo "We're full, please wait {$bucket->getWait()} ms\n";
}
else {
// Do things.
}
// Big drip.
$bucket->drip(20);
// Named drip (10 drips).
$bucket->drip('POST');
// Write out the status to the headers for easy debugging.
$bucket->writeHeaders();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.