In-depth understanding of PHP output Caching (output_buffering) _php Tutorials

Source: Internet
Author: User
Tags sapi
First, clear the output sequence of PHP
1. PHP output cache is turned on: Echo,print, PHP output_buffring, server buffering, browser buffering display
2. PHP output Cache is not open: Echo,print, server buffering, browser buffering, browser display

Also clear the browser output cache: IE 256Bytes, Chrome and Firefox 1000Bytes, only the output data reached this length or script end browser will be output data on the page

again, there are several PHP settings and APIs that you can use:
Output_buffering configuration in the 1.php.ini
off: Indicates closing PHP output cache
on: Open an infinitely large output cache
• 4096: Open output cache with size 4096Byte

Implicit_flush configuration in the 2.php.ini
on: Indicates that the flush () function is automatically called after each output (such as Echo,print), and the direct output
off: On the contrary, flush () will not be called after each output, it will need to wait until the server buffering full before output, but we can use the flush () function instead of it, not open it's OK, but more flexible

3.ob_flush () function: Take out the data in PHP buffering and put it into the server buffering

4.flush () Function: Remove the data from the server buffering and put it into browser buffering

5.ob_start () function:For this function I do not understand very clearly, because the output will not be controlled by Ob_flush (), even if the use of Ob_flush () and flush (), the data is not immediately output in the browser. Now know that if Output_buffering=off, Even if Ob_start () is used, the output data cannot be cached, and if output_buffering=on, even without Ob_start (), the output data can be cached by PHP, so I think Ob_start is more useless, for the time being, regardless of his

Then let's look at the code (set Output_buffering=4096,implicit_flush=off)
Copy CodeThe code is as follows:


Ob_start (); If this thing is open, it will not be normal, the output is not controlled by Ob_flush (), do not know what to do with
Echo str_repeat (', 1000); IE Cache 256Bytes
Echo str_repeat (', 1000); Chrome and FF cache 1000Bytes, which is used to first use the browser cache, but it is doubtful why this line of output is not saved by output_buffering, but directly output
for ($i =0; $i <5; $i + +) {
echo $i. '
';
Ob_flush ();
Flush ();
Sleep (1);
}
?>



Here the code output is a row of output, the specific principle of reference to the Ob_flush () and flush () function of the effect
These two functions are missing any one of my settings is to wait until 0, 1, 2, 3, 4 are cached and last together.
Finally quoted a section of Laruence blog, I hope that everyone's understanding to help

Ob_flush/flush's description in the manual, is to refresh the output buffer, and also need to be used, so it will cause many people confused ...

In fact, the two of them are different objects, in some cases, flush does not do anything at all.

The Ob_* series function is the output buffer that operates PHP itself.

So, Ob_flush is the buffer that refreshes PHP itself.

Flush, strictly speaking, this only works when PHP is installed as an Apache module (handler or filter). It is a buffer that refreshes the webserver (which can be considered specifically Apache).

Under Apache module's SAPI, flush will invoke Sapi_module's flush member function pointer indirectly, calling Apache's Api:ap_rflush to flush Apache's output buffer, and of course the manual says, There are some Apache other modules that may change the result of this action:
1. Some Apache modules, such as Mod_gzip, may have their own output cache,
2. This causes the flush () function to produce results that are not immediately sent to the client browser.
3.
4. Even the browser will cache the received content before it is displayed. such as Netscape
5. The browser caches the content before it accepts the start of a newline or HTML tag, and
6. The entire table is not displayed until the token is accepted.
7.
8. Some versions of Microsoft Internet Explorer only receive 256
9. The byte does not start to display this page, so you must send some extra space to make this
10. Some browsers display the contents of the page.
So, the correct use of the two is the order. First Ob_flush, then flush,
Of course, in other sapi, do not call flush also can, only to ensure that your code portability, recommended for use.

http://www.bkjia.com/PHPjc/327577.html www.bkjia.com true http://www.bkjia.com/PHPjc/327577.html techarticle first, clear the output sequence of PHP 1. Open PHP Output cache: echo,print-php output_buffring-server buffering-browser buffering-browser Display 2. PHP output cache is not open ...

  • 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.