The accelerated display of dynamic website content is very important. This article discusses several functions of PHP in depth, proposed solutions for PHP web page compression and buffering. I. introduced several functions that control PHP output. PHP4 adopts a buffer mechanism. Before you decide to send the function, all the content only exists in the buffer, instead of SyntaxHighlighter. all ();
The accelerated display of dynamic website content is very important. This article discusses several functions of PHP in depth, proposed solutions for PHP web page compression and buffering. I. introduced several functions that control PHP output. PHP4 adopts a buffer mechanism. Before you decide to send the function, all the content only exists in the buffer, instead of sending it directly to the browser, although you can use the header and setcookie functions, these two functions are just a bit of a "artifact" compared to the powerful output functions ". Let's take a look at the true capabilities of these functions: void ob_start (void); this function tells the PHP processor to redirect all the output to the internal buffer. after calling this function, no output 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 use this function before outputting data to the browser. Void ob_implicit_flush ([int flag]) This function is used to control implicit buffer purging. the default value is off. if it is enabled, the results of each print/echo or output command are sent to the browser. 2. use Output Control to compress PHP output before starting. ensure that Zlib is supported during your PHP4 compilation. First, initialize the output buffer: Then all output content is generated. After the page is generated, use: We also need to check whether the browser supports data compression by checking "gzip, deflate" in the variable $ HTTP_ACCEPT_ENCODING: The following describes how to generate gzip output: 3. buffering PHP output can easily implement caching in PHP4. let's look at the example: IV. conclusion 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.