This is a PHP port of https://github.com/cenkalti/backoff (thanks, @cenkalti), which is a port of the exponential backoff algorithm from Google's HTTP Client Library for Java.
Exponential backoff is an algorithm that uses feedback to multiplicatively decrease the rate of some process, in order to gradually find an acceptable rate. The retries exponentially increase and stop increasing when a certain threshold is met.
Retry with default exponential backoff.
(new Retry(function () {
// workload ...
}))();
$operation = function () {
// workload ...
if ($somePermanentFailCondition) {
throw new \Ekomobile\Retry\Exception\Permanent(new \Exception('Unretryable error'))
}
// ...
throw new Exception('Retryable error')
};
$backoff = new \Ekomobile\Retry\Backoff\WithMaxRetries(new \Ekomobile\Retry\Backoff\Exponential(), 5);
$notify = function (\Throwable $e) {
// $logger->log($e);
};
$retry = new \Ekomobile\Retry\Retry($operation, $backoff, $notify);
$retry();