PHP Ob_flush,flush in IE buffer ineffective solution _php tips

Source: Internet
Author: User
Tags flush
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);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.