note 116748 added to function.ob-implicit-flush
| From: | PedroGimeno | Date: | Sun, 22 Feb 2015 18:11:56 +0000 |
| Subject: | note 116748 added to function.ob-implicit-flush | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201784@lists.php.net to get a copy of this message | ||
Note that the name ob_implicit_flush is misleading. Despite its name, this function does NOT work
with the user output buffer, i.e. the one that the rest of the ob_* functions work with. It will NOT
do an automatic ob_flush(). It will do an automatic flush(). Different things.
For example, the following script:
<?php
ob_implicit_flush();
for($i = 0; $i < 10; $i++)
{
echo "$i\n";
sleep(1);
}
?>
will be equivalent to this one:
<?php
for ($i = 0; $i < 10; $i++)
{
echo "$i\n";
flush();
sleep(1);
}
?>
That script will not output anything until the end, if 'output_buffering' is set to
'on' in php.ini. Unfortunately, there is no way to do an implicit ob_flush() after each
output, that I am aware of.
If you want the output to come out as it is generated, one solution is to *also* add ob_end_clean()
or ob_end_flush() to the beginning of the script:
<?php
ob_end_flush();
ob_implicit_flush();
for ($i = 0; $i < 10; $i++)
{
echo "$i\n";
sleep(1);
}
?>
This will output as it goes. This is only a problem if you only want one part of the output to come
out in real time, and want the rest buffered. In that case, since there's no function to do an
implicit ob_flush() every time, you need to call it explicitly. For example, this works:
<?php
ob_start(); // not needed if output_buffering is on in php.ini
ob_implicit_flush(); // implicitly calls flush() after every ob_flush()
echo "This output is buffered.\n";
echo "As is this.\n";
for ($i = 0; $i < 10; $i++)
{
echo "$i\n";
ob_flush();
sleep(1);
}
?>
Note also that some browsers may wait until they have a certain amount of output. See flush [ http://php.net/manual/en/function.flush.php ]
for details. It was my case with Firefox (Iceweasel 17.0); unless I output 1024 bytes at the
beginning, it does not begin to output.
----
Server IP: 72.52.91.14
Probable Submitter: 176.108.160.241
----
Manual Page -- http://php.net/manual/en/function.ob-implicit-flush.php
Edit -- https://master.php.net/note/edit/116748
Del: integrated -- https://master.php.net/note/delete/116748/integrated
Del: useless -- https://master.php.net/note/delete/116748/useless
Del: bad code -- https://master.php.net/note/delete/116748/bad+code
Del: spam -- https://master.php.net/note/delete/116748/spam
Del: non-english -- https://master.php.net/note/delete/116748/non-english
Del: in docs -- https://master.php.net/note/delete/116748/in+docs
Del: other reasons-- https://master.php.net/note/delete/116748
Reject -- https://master.php.net/note/reject/116748
Search -- https://master.php.net/manage/user-notes.php