Describes how to buffer and compress PHP dynamic content.

Source: Internet
Author: User
PHP4 uses a buffer mechanism. Before you decide to send, all content is stored in the buffer instead of directly sent to the browser. although you can use the header and setcookie functions, however, these two functions use a buffer mechanism compared to the powerful PHP4 function. Before you decide to send the function, all the content is stored in the buffer, rather than directly sent to the browser, although you can use the header and setcookie functions, these two functions are just a bit of a "trick" compared to the powerful output functions ". Let's take a look at the true capabilities of these functions:

Void ob_start (void );

This function instructs the PHP processor to redirect all output to the internal buffer. after this function is called, no output will be made to the browser.

String ob_get_contents (void );

This function returns the output buffer to a string. you can send the accumulated output together to the browser. Of course, you must first turn off the buffer.

Int ob_get_length (void );

This function returns the length of the output buffer.

Void ob_end_clean (void );

This function clears and closes the buffer. You need to apply this function before outputting it to the browser.

Void ob_implicit_flush ([int flag])

This function is used to control the implicit buffer for outbound traffic. the default value is off. if this function is enabled, the output of each print/echo or output command is sent to the browser.

II. Use output control to compress PHP output


Before you begin, make sure that your PHP4 compilation supports Zlib.

First, initialize the output buffer:

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.