- mt_rand: documentation ( source)
<?php
function retry($retries, callable $fn)
{
beginning:
try {
return $fn();
} catch (\Exception $e) {
if (!$retries) {
throw new \Exception('', 0, $e);
}
$retries--;
goto beginning;
}
}
$fn = function() {
if (mt_rand(0, 5) === 0)
{
return true;
}
throw new \Exception('nope');
};
retry(10, $fn);