Reputation: 4663
I want to echo string dynamically, not all of them at once when script finished running. Tried this one, but it echos all of them when script finished running. How can I echo values dynamically ?
<?php
ob_start();
echo "Line #1...<br>";
ob_flush();
flush();
sleep(2);
echo "Line #2...<br>";
ob_flush();
flush();
sleep(2);
echo "Line #4...<br>";
?>
Upvotes: 1
Views: 127
Reputation: 28151
Try sending a line-ending like \n or append at least 256 spaces to each echo to trigger the browser.
Some browsers will wait for at least 256bytes before rendering, others need a newline char. Try this combination before each flush:
echo str_repeat(" ", 256) . "\n";
Other cause could be the webserver that is caching the response.
Upvotes: 2