PHP ob_flush,flush in IE buffer Invalid solution _php Tutorial

Source: Internet
Author: User
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 ...

  • Related Article

    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.