note 47312 deleted from function.flush by danbrown
| From: | danbrown@php.net | Date: | Sat, 14 Feb 2009 06:09:35 +0000 |
| Subject: | note 47312 deleted from function.flush by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150660@lists.php.net to get a copy of this message | ||
Note Submitter: mat.wilmots (at) wanadoo (dot) fr
----
This code does not work as expected
<pre>
<?php
echo "Test1\n";
flush();
sleep(3);
echo "Test2\n";
?>
</pre>
It should print Test1, wait 3 seconds then print Test2 but actually it prints everything at the end.
It seems PHP is doing output buffering on its own, here is the way to make it work :
<pre>
<?php
ob_end_flush();
echo "Test1\n";
flush();
sleep(3);
echo "Test2\n";
?>
</pre>
You don't really need to repeat some "fake" text to fill the buffer in order to make
this effect.