Home > Backend Development > PHP Tutorial > Examples explaining the buffering and compression of PHP dynamic content_PHP Tutorial

Examples explaining the buffering and compression of PHP dynamic content_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:12:10
Original
836 people have browsed it

PHP4 adopts a buffering mechanism. Before you decide to send, all content only exists in the buffer instead of being sent directly to the browser. Although you can use the header and setcookie functions to achieve this, these two functions are not as powerful as The output function is just a little trick. Let's take a look at the real capabilities of these functions:
void ob_start (void );
This function tells the PHP processor to redirect all output to the internal buffer. After calling this function, There will be no output to the browser.
 
string ob_get_contents( void) ;
This function returns the output buffer to a string, which you can use to send the stacked output to the browser. Of course you have to turn off buffering first.
 
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 use this function before outputting to the browser.
 
void ob_implicit_flush ([int flag])
This function is used to control implicit buffer flushing. The default is off. If it is turned on, it will be flushed for each print/echo or The results of the output command are sent to the browser.
 

2. Use output control to compress PHP output
Before you start, make sure your PHP4 compiler supports Zlib.

First, initialize the output buffer:
The PHP output buffer function is very useful in operating script output. Compressing the buffered output can reduce the output time by 80%, which is useful for accessing other data resources (such as databases) or XML), it is also a good buffering mechanism

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/629514.htmlTechArticlePHP4 adopts a buffering mechanism. Before you decide to send, all content only exists in the buffer instead of being sent directly. To the browser, although you can use the header and setcookie functions to implement...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template