Home  >  Article  >  Backend Development  >  Working hard to speed up PHP programs_PHP Tutorial

Working hard to speed up PHP programs_PHP Tutorial

WBOY
WBOYOriginal
2016-07-13 17:28:22902browse

It is very important to accelerate the display of content on dynamic websites. This article proposes a solution for PHP web page compression and buffering through an in-depth discussion of several PHP functions. 1. Introducing several functions that control PHP output. PHP4 adopts a buffering mechanism. When you decide to send Previously, everything just existed in the buffer instead of being sent directly to the browser. Although you could use the header and setcookie functions to achieve this, these two functions were just a "little trick" compared to the powerful output function. Let's take a look at what these functions are really about: 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, the results of each print/echo or output command will be sent to the browser. 2. Use output control to compress PHP output. Before starting, make sure your PHP4 compiler supports Zlib. First, initialize the output buffer: and then generate all output content. After the page is generated, use: Also check whether the browser supports compressed data. We use the method of checking "gzip, deflate" in the variable $HTTP_ACCEPT_ENCODING: Let's analyze how to generate gzip output: 3. Buffering PHP output can be easily buffered in PHP4. Let’s look at an example: 4. Conclusion The PHP output buffer function is very useful in operating script output. The output after buffering compression can be reduced by 80%. output time, which is also a good buffering mechanism for accessing other data resources (such as databases or XML).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531787.htmlTechArticleIt is very important to accelerate the content display of dynamic websites. This article proposes a PHP web page through an in-depth discussion of several PHP functions. Compression and buffering solutions 1. Introduce several ways to control PHP output...
Statement:
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