Skip to content

Instantly share code, notes, and snippets.

@alexwilson
Created November 26, 2022 20:40
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 alexwilson/5ab35e1b76da89080cea66c038193d05 to your computer and use it in GitHub Desktop.
Save alexwilson/5ab35e1b76da89080cea66c038193d05 to your computer and use it in GitHub Desktop.
Continuously retry something in PHP
<?php
set_error_handler(
function ($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
);
function executeCode(){
echo "Hello world!";
}
$NUM_OF_ATTEMPTS = 5;
$attempts = 0;
do {
try
{
executeCode();
} catch (Exception $e) {
$attempts++;
sleep(1);
continue;
}
break;
} while($attempts < $NUM_OF_ATTEMPTS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment