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

Source: Internet
Author: User
Tags sapi
Ob_flush/flush in the manual description, are refreshing output buffer, and also need to support the use, so will lead to a lot of people confused ...
In fact, they are different objects of operation, in some cases, flush do not do anything at all.
The Ob_* series function is the output buffer that operates on PHP itself.
So, Ob_flush is the buffer that refreshes PHP itself.
And flush, strictly speaking, this only in PHP as the Apache module (handler or filter) installed when the actual role. It is a buffer that refreshes the webserver (which can be considered specifically Apache).
Under the SAPI of Apache module, flush invokes the Flush member function pointer of the sapi_module and indirectly invokes Apache's Api:ap_rflush to refresh the Apache output buffer, which is also stated in the manual. There are some other Apache modules that may change the results of this action.
Some Apache modules, such as Mod_gzip, may have their own output caching, which will result in the results of the flush () function not being immediately sent to the client browser.
Even browsers will cache what they receive before it is displayed. For example, Netscape browser caches content before it accepts the start of a newline or HTML tag, and does not display the entire table until the </table> tag is accepted.
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.
So, the order in which the two are used correctly is. First Ob_flush, then flush,
Of course, in other sapi, do not call the flush can also, just to ensure that your code portability, recommended supporting use.
In IE, you must output 256 bytes before it works, following code:
Copy Code code as follows:

function Execte () {
echo Str_pad ("", 256);
For ($i =1 $i <10; $i + +) {
echo $i. " <Br> ";
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.