As a walking river for many years old Chinese medicine, today ordered to solve a case of front-end page display slow problem. The following is the case for the issue page:
Apache + PHP
Output content using the Smarty template
The final output content of the page is larger, 80k+
Page execution time is above 500ms
Sacrifice a magic weapon xhprof to the problem page to do a detailed inspection, found that the bottleneck of the page is a template (compiled) in an echo statement, the Echo statement output of the string is larger, probably 50k+ bytes, spending time of more than 400 milliseconds, accounting for the entire page execution time of 80%. Such echo output in the site home page is actually a very common thing, no database operation, according to the reason that the execution time should not be so long.
So violently using the search skills, and finally found some clues in the echo section of the PHP manual, as early as 2003, the predecessor thought that through the echo output large string to the client will cause the server performance problem, according to my test, in this scenario, using print is actually the same slow. The recommended solution is to cut the string into a smaller string output, the presentation speed will be improved, the output function is as follows:
But the above prescription is not very symptomatic, the entire ECHOBIG output time is still about 400 milliseconds, not much improvement. Considering that the output of a large number of content to the client is slow, so check the configuration of Apache, the original has not opened deflate compression, then enabled. Using Xhprof again, this echo's output time is reduced to around 5ms. 400ms to 5ms, a configuration problem will produce 80 times times the gap, it is really save the old money.
This story tells us that it is really important to turn on the compression output.
Articles you may be interested in
- Use PHP function memory_get_usage to get the current PHP memory consumption to achieve program performance optimization
- PHP gets all the picture lists in the content and outputs the method
- PHP gets a method for each month in a certain period of time, returning an array of these months
- PHP converts consecutive spaces in a string to a space
- How to use zlib to compress output content to improve Web page opening speed
- Text area textarea box based on input self-adapting height
- PHP programmers must know 40 of the PHP code optimization
- JavaScript to share content to the major social platform website code summary
http://www.bkjia.com/PHPjc/764090.html www.bkjia.com true http://www.bkjia.com/PHPjc/764090.html techarticle as a walking river for many years old Chinese medicine, today ordered to solve a case of front-end page display slow problem. The problem page is as follows: Apache + PHP uses smarty template output content page ...