PHP output cache based output_buffering instance detailed

Source: Internet
Author: User
Tags sapi browser cache
first, clear the output sequence of PHP

1. Open the PHP output cache:Echo,print, PHP output_buffring, server buffering, browser buffering display
2. The 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 will not be immediately output in the browser. Now know that if output_buffering= OFF, even if the use of Ob_start (), is also unable to cache the output data, and if output_buffering=on, even without ob_start (), output data can also be PHP cache, so feel ob_start compared to waste, temporarily regardless of his

Then let's look at the code (set Output_buffering=4096,implicit_flush=off)



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 </table> tag 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. Therefore, the correct use of the two is the order. Ob_flush first, then flush,
Of course, in other sapi, do not call flush also can, only to ensure that your code portability, recommended for use.

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.