Created
November 26, 2022 20:40
-
-
Save alexwilson/5ab35e1b76da89080cea66c038193d05 to your computer and use it in GitHub Desktop.
Continuously retry something in PHP
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
<?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