1. Go to this page and download the library: Download kdn/attempts-counter 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/ */
kdn / attempts-counter example snippets
use kdn\attemptsCounter\Action;
$contents = false;
$action = new Action('query-url', 10, 3 * 10 ** 9); // up to 10 attempts, 3 seconds delay between attempts
while ($contents === false) {
$contents = @file_get_contents('https://unreliable.site');
$action->increment();
}
var_dump($contents);
use kdn\attemptsCounter\Action;
use kdn\attemptsCounter\AttemptsCounter;
function generateId() {
return mt_rand(0, 30);
}
$ids = [];
$counter = new AttemptsCounter();
$counter->addAction(new Action('generate-unique', 5))
->addAction(new Action('generate-odd', 10));
while (count($ids) < 10) {
$id = generateId();
if ($id % 2 === 0) {
$counter->getAction('generate-odd')->increment();
continue;
}
if (in_array($id, $ids, true)) {
$counter->getAction('generate-unique')->increment();
continue;
}
$ids[] = $id;
}
var_dump($ids);
sh
php composer.phar
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.