Created
September 27, 2014 22:49
-
-
Save leedavis81/90ce556d7043a70ec477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function igorRetry($retries, callable $fn) | |
{ | |
beginning: | |
try { | |
return $fn(); | |
} catch (\Exception $e) { | |
if (!$retries) { | |
throw new \Exception('', 0, $e); | |
} | |
$retries--; | |
goto beginning; | |
} | |
} | |
$fn = function() { | |
if ($GLOBALS['counter'] > 0) | |
{ | |
$GLOBALS['counter']--; | |
throw new \Exception('Try again'); | |
} | |
return true; | |
}; | |
$start = microtime(true); | |
try { | |
$GLOBALS['counter'] = 999999; | |
igorRetry(1000000, $fn); | |
} catch (\Exception $e) {} | |
echo 'Igor retry finished in: ' . (microtime(true) -$start) . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment