PHP programs are buffered, regardless of the circumstances in which PHP executes (CGI, Web servers, 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 the Flush () functions to refresh the output buffer.
Individual Web server programs, especially Web server programs under Win32, still cache the output of the script until the end of the program before sending the results to the browser.
Write a small example of yourself and want to output a number every second of the page.
Follow the online code:
Copy Code code as follows:
Ob_end_clean ();
for ($i =10; $i >0; $i-)
{
echo $i;
Flush ();
Sleep (1);
}
Or:
Copy Code code 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, it was 10 digits out each time, indicating that the buffer was not in effect.
I also began to adjust the php.ini inside the output_buffering settings, restart Apache, still ineffective.
Then I saw a passage:
Some versions of Microsoft Internet Explorer will only start displaying the page after the 256 bytes received, so you must send some extra spaces to allow the browsers to display the page content.
Evil of IE browser, the problem is more TMD!
Then I changed the program, and it was normal:
Copy Code code as follows:
Echo Str_pad (', 4096);
for ($i = 0; $i < $i + +) {
echo $i;
Ob_flush ();
Flush ();
Sleep (1);
}
Copy Code code as follows:
//ob_end_flush ();//ie8 does not Work
Echo Str_pad ("", 256); IE needs to accept 256 bytes before it starts displaying
for ($i =0 $i <18; $i + +) {
echo $i;
Flush ();
Sleep (1);
}