3v4l.org

run code in 300+ PHP versions simultaneously
<?php function retry($retries, callable $fn) { while (true) { try { return $fn(); $retries--; } catch (\Exception $e) { if (!$retries) { throw new \Exception('', 0, $e); } } } } $fn = function() { if ($GLOBALS['counter'] > 0) { $GLOBALS['counter']--; throw new \Exception('Try again'); } return 'something successfull'; }; $start = microtime(true); try { $GLOBALS['counter'] = 999999; retry(1000000, $fn); } catch (\Exception $e) {} echo 'Retry finished in: ' . (microtime(true) -$start) . "\n";

preferences:
26.2 ms | 402 KiB | 5 Q