Created
June 10, 2020 13:11
-
-
Save rakeshsoni18/a632c2cc539b641a16fb53ee90067da2 to your computer and use it in GitHub Desktop.
Retry After an Exception in a PHP Try-Catch Block
This file contains hidden or 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
/** | |
* Basic structure for retrying when an exception is thrown in a try/catch block. | |
* This example fails through three retries simply to illustrate the behavior. | |
*/ | |
$retries = 3; | |
for ($try = 0; $try < $retries; $try++) { | |
try { | |
throw new \Exception('bad mojo'); | |
} catch (\Exception $e) { | |
var_dump('failed ' . $try); | |
sleep(1); | |
continue; | |
} | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment