PHP line-by-line output (combination of ob_flush and flush)

Source: Internet
Author: User
The descriptions of ob_flushflush in the manual are to refresh the output buffer and must be used together, which may lead to confusion.

Ob_flush/flush descriptions in the manual are used to refresh the output buffer and must be used together, which may lead to confusion.

Ob_flush/flush descriptions in the manual are used to refresh the output buffer and must be used together, which may lead to many confusion...
In fact, they have different operation objects. In some cases, flush does nothing at all ..
Ob _ * series functions are used to operate the output buffer of PHP itself.
Therefore, ob_flush is used to refresh the PHP buffer.
But flush, strictly speaking, this is only useful when PHP is installed as an apache Module (handler or filter. it is used to refresh the buffer zone of the WebServer (which can be considered to be specific to apache.
In the sapi of apache module, flush indirectly calls apache api: ap_rflush to refresh apache output buffer by calling the flush member function pointer of sapi_module, some other modules of apache may change the result of this action ..
Some Apache modules, such as mod_gzip, May output the cache by themselves, which will cause the results produced by the flush () function to be not immediately sent to the client browser.
Even the browser caches the received content before it is displayed. For example, the Netscape Browser caches content before receiving a line break or the beginning of an html Tag, and receivesThe entire table is not displayed until it is marked.
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.
Therefore, the correct order of the two users is: first ob_flush, then flush,
Of course, other sapis do not call flush, but we recommend that you use it to ensure the portability of your code.
In IE, it takes effect only after 256 bytes are output. The following code:
The Code is as follows:
Function execte (){
Echo str_pad ("", 256 );
For ($ I = 1; $ I <10; $ I ++ ){
Echo $ I ."
";
Ob_flush ();
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.