Skip to content

Instantly share code, notes, and snippets.

@shawnlindstrom
Last active November 27, 2018 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shawnlindstrom/a8806cccd52634fe567eb731d919d22e to your computer and use it in GitHub Desktop.
Save shawnlindstrom/a8806cccd52634fe567eb731d919d22e to your computer and use it in GitHub Desktop.
PHP Try/Retry on Exception
<?php
/**
* 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