1. Go to this page and download the library: Download fostam/retry 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/ */
fostam / retry example snippets
try {
// sleep 1 second between attempts
$funcResult = Retry::onFailure('myfunc', 3, new ConstantDelayPolicy(1000));
}
catch (RetryLimitException $e) {
// failed after maximum number of attempts
}
// success before maximum number of attempts have been exceeded
// sleep 2, 2, 4, 20, 20, 20, 20 ... (stick to last value after series has ended)
$policy = new SeriesDelayPolicy([2000, 2000, 4000, 20000]);
// sleep 2, 2, 4, 20, 2, 2, 4, 20, 2, 2, 4, ... (repeat series after it has ended)
$policy = new SeriesDelayPolicy([2000, 2000, 4000, 20000], true);
// sleep a random amount between 1900 and 2100 milliseconds
$policy = new JitterDelayPolicy(2000, 100);
// don't sleep at all
$policy = new NoneDelayPolicy();
// retry without delay
Retry::onFailure('myfunc', 3);
Retry::onFailure('myfunc', 3, null, $tries);
print "success after {$tries} attempts";
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.