Skip to content

Instantly share code, notes, and snippets.

@mishak87
Created September 25, 2012 20:56
Show Gist options
  • Save mishak87/3784384 to your computer and use it in GitHub Desktop.
Save mishak87/3784384 to your computer and use it in GitHub Desktop.
Exponential backoff
$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