Phpob_flush, how to buffer invalid content in ie _ PHP Tutorial

Source: Internet
Author: User
Phpob_flush, and flush buffer in ie are invalid solutions. The buffer of the PHP program, regardless of the circumstances in which PHP is executed (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 buffer PHP programs, regardless of the situation in which PHP is executed (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 cache mode of the server or client browser. Therefore, you must use both the ob_flush () and flush () functions to refresh the output buffer.
Some web server programs, especially the web server programs under Win32, will cache the script output until the program ends before sending the results to the browser.
I wrote a small example to output a number every second on the page.

Follow the online code:

The code is as follows:


Ob_end_clean ();
For ($ I = 10; $ I> 0; $ I --)
{
Echo $ I;
Flush ();
Sleep (1 );
}



Or:

The code is as follows:


For ($ I = 10; $ I> 0; $ I --)
{
Echo $ I;
Ob_flush ();
Flush ();
Sleep (1 );
}



I found that it takes effect in Firefox, but it does not take effect in IE. each time it is output with 10 numbers, this indicates that the buffer has not taken effect.

I started to adjust the output_buffering settings in php. ini, and restarted apache, which is still invalid.

Then I saw a passage:

In some versions of Microsoft Internet Explorer, the page is displayed only after 256 bytes are received. Therefore, some extra spaces must be sent for these browsers to display the page content.

The evil IE browser has many TMD problems!

Then I modified the program and it was normal:

The code is as follows:


Echo str_pad (', 4096 );
For ($ I = 0; $ I <10; $ I ++ ){
Echo $ I;
Ob_flush ();
Flush ();
Sleep (1 );
}


The code is as follows:


// Ob_end_flush (); // IE8 does not work
Echo str_pad ("", 256); // IE must receive 256 bytes before Display starts

For ($ I = 0; $ I <18; $ I ++ ){
Echo $ I;
Flush ();
Sleep (1 );
}

CGI, web server, and so on ). This function sends all the output of the program so far to the user's browser. The flush () function does not...

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.