Instance description PHP dynamic content buffer and compression
Source: Internet
Author: User
PHP4 uses a buffer mechanism. Before you decide to send, all content is stored in the buffer, rather than directly sent to the browser. although you can use the header and setcookie functions, however, these two functions are just a little bit of "skill" compared to the powerful output functions ". Let's take a look at the true capabilities of these functions: voidob_start (vo PHP4 uses a buffer mechanism. 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 disables the buffer. You need to use this function before outputting data to the browser.
Void ob_implicit_flush ([int flag])
This function is used to control implicit buffering and purging. the default value is off. if it is enabled, the results of each print/echo or output command are sent to the browser.
II. Use output control to compress PHP output
Before you start, make sure that your PHP4 compilation supports Zlib.
First, initialize the output buffer:
Ob_start ();
Ob_implicit_flush (0 );
?>
Then all output content is generated.
Print ("This example shows compressed output! ");
?>
The PHP output buffer function is very useful in script output operations. compressing the buffer can reduce the output time by 80%, which is used to access other data resources (such as databases or XML, it is also a good buffer mechanism.
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