Created
September 25, 2012 20:56
-
-
Save mishak87/3784384 to your computer and use it in GitHub Desktop.
Exponential backoff
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
$stopAt = 15; // 4h 33m 4s | |
$now = new DateTime; | |
?><table><?php | |
foreach (range(1, 15) as $i) { | |
?><tr><td><?php | |
echo $i | |
?><td><?php | |
$after = clone $now; | |
$tries = min($i, $stopAt); | |
$seconds = (int) ceil( (pow(2, $tries) - 1) / 2 ); | |
$interval = new DateInterval('PT' . $seconds . 'S'); | |
$after->add($interval); | |
echo $after->format($format = 'Y-m-d H:i:s'); | |
?><td><?php | |
$d = new DateTime('@' . $seconds); | |
echo $d->format('H:i:s'); | |
?><td><?php | |
echo $seconds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment