php output with sleep()

I just hashed through this same problem from a beginner perspective and came up with this bare-bones script which will do what you want.

<?PHP
ob_start();
$buffer = str_repeat(" ", 4096)."\r\n<span></span>\r\n";

for ($i=0; $i<25; $i++) {
  echo $buffer.$i;
  ob_flush();
  flush();
  sleep(1);
}

ob_end_flush();
?>

Questions that you may ask could be here (about \r\n) and here (about ob_flush()). Hope that helps you out.

Leave a Comment