Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple Retrying for loop example
<?php
$retries = 0;
$maxRetries = 3;
// Should fail this amount of times
$failCounter = 5;
for($i = 0; $i < 10; $i++) {
var_dump($i);
// Induce failure
if ($failCounter > 0) {
$failCounter--;
var_dump("FAILED");
// Failed, retry
if ($retries < $maxRetries) {
$i--; // Reset index back to the failed index
$retries++;
} else {
var_dump("Failed max times");
$retries = 0;
continue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.