Home > Backend Development > PHP Tutorial > php ob_flush, flush buffer invalid solution in IE_PHP tutorial

php ob_flush, flush buffer invalid solution in IE_PHP tutorial

WBOY
Release: 2016-07-21 15:37:58
Original
948 people have browsed it

Buffering of PHP programs regardless of the context in which PHP is executed (CGI, web server, etc.). This function sends all the program's output so far to the user's browser.
The flush() function has no effect on the cache mode of the server or client browser. Therefore, both the ob_flush() and flush() functions must be used to flush the output buffer.
Some web server programs, especially web server programs under Win32, will still cache the output of the script until the end of the program before sending the results to the browser.
I wrote a small example myself and wanted to add it to the page every time. Outputs a number every second.

Follow the code on the Internet:

Copy the code The code is as follows:

ob_end_clean();
for ($i=10; $i>0; $i--)
{
echo $i;
flush();
sleep(1);
}


Or:
Copy code The code is as follows:

for ($i=10; $i>0; $i--)
{
echo $i;
ob_flush();
flush();
sleep(1);
}


I found that it works in Firefox, but not in IE. 10 numbers are output together every time, which means that buffering is not effective.

I started adjusting the output_buffering settings in php.ini and restarted apache, but it still didn't work.

Then I saw this paragraph:

Some versions of Microsoft Internet Explorer only start displaying the page after receiving 256 bytes, so some extra spaces must be sent to allow These browsers display page content.

The evil IE browser has a lot of trouble!

Then I modified the program and it worked normally:
Copy the code The code is as follows:

echo str_pad('',4096);
for ($i = 0; $i < 10; $i++) {
echo $i;
ob_flush();
flush();
sleep(1);
}

Copy code The code is as follows:

/ /ob_end_flush();//It doesn’t work under IE8
echo str_pad(" ", 256);//IE needs to receive 256 bytes before it starts to display

for($i=0 ;$i<18;$i++) {
echo $i;
flush();
sleep(1);
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/321813.htmlTechArticleBuffering of PHP programs, regardless of the circumstances under which PHP is executed (CGI, web server, etc.). This function sends all the program's output so far to the user's browser. The flush() function does not...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template