PHP program buffering, regardless of the circumstances in which PHP executes (CGI, Web server, etc.). This function sends all the output of the program so far to the user's browser.
The flush () function does not affect the caching mode of the server or client browser. Therefore, you must use both the Ob_flush () and flush () functions to flush the output buffers.
Individual 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, want to output a number of pages every second.
Follow the online code:
Copy CodeThe code is as follows:
Ob_end_clean ();
for ($i =10; $i >0; $i--)
{
echo $i;
Flush ();
Sleep (1);
}
Or:
Copy CodeThe code is as follows:
for ($i =10; $i >0; $i--)
{
echo $i;
Ob_flush ();
Flush ();
Sleep (1);
}
I found that it worked in Firefox, but it didn't work in IE, and each time it was output with 10 numbers, which indicated that the buffer was not in effect.
I began to adjust the php.ini inside the output_buffering settings, restart Apache, still invalid.
Then I saw a passage:
Some versions of Microsoft Internet Explorer do not start to display the page until 256 bytes are accepted, so you must send some extra spaces to let these browsers display the page content.
Evil IE Browser, the problem is more TMD!
Then I modified the next program, it is normal:
Copy CodeThe code is as follows:
Echo Str_pad (', 4096);
for ($i = 0; $i < $i + +) {
echo $i;
Ob_flush ();
Flush ();
Sleep (1);
}
Copy CodeThe code is as follows:
Ob_end_flush ();//ie8 's not working.
echo Str_pad ("", "N");//ie needs to accept 256 bytes before starting to show
for ($i =0; $i <18; $i + +) {
echo $i;
Flush ();
Sleep (1);
}
http://www.bkjia.com/PHPjc/321813.html www.bkjia.com true http://www.bkjia.com/PHPjc/321813.html techarticle PHP program buffering, regardless of the circumstances in which PHP executes (CGI, Web server, etc.). This function sends all the output of the program so far to the user's browser. The flush () function does not ...