Created
February 15, 2017 07:49
-
-
Save HelgeSverre/75088df52b4cf28048171eeeb8af7f92 to your computer and use it in GitHub Desktop.
Simple Retrying for loop example
This file contains 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 | |
$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