First, the basic knowledge of PHP itself, functions, constants, and so on, as far as possible with the built-in method to solve the problem (because the personal writing often does not have a built-in method of high-performance);
Second, the code as little as possible to implement the function (because the PHP implementation is actually, our code first processed into the underlying language for machine execution, if the code is many, the content of the conversion more natural time-consuming);
Third, the optimization can be carried out through the pressure test AB test their own code, and the code optimization, again pressure measurement efficiency;
Four, less with the @ symbol;
Use Unset () function to write off the variables.
Six, less use regular expression, double-edged sword;
Seven, avoid cycle for loop condition;
Eight, the key value of the array, be sure to use the quoted string as the key value, why do you do this?
When $arr = Array ("key" = "hehe"); $arr ["Key"] is correct, efficiency-enhancing
$arr [key] is not a good way to do this without quotes, because when PHP executes, it finds that key has no quotation marks.
At this point, he will go to check if key is a constant, if the error mechanism to open errors will prompt notice
The constant is not found for key. If you add quotation marks, PHP will go directly into the $arr array to find the key value for key,
relative efficiency is efficient.
Ix. external factors that affect PHP performance are:
The revelation of this point is that when a website is slow, it may not be the performance of PHP itself is slow, may be a network problem, may be a hardware problem, etc., as an architect to troubleshoot the problem can not stay in the program optimization!
Ten, read the memory content is less efficient than reading the database content, so that large traffic speed-up site often with Memcache, Redis and other distributed cache cache data to memory, and then first and memory to read the data;
Xi. through Xhporf (test PHP performance analysis tools from Facebook), you can test the process of visiting the website, and can be quickly found through the area of the flowchart marked red, time-consuming method, to optimize the method;
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
PHP Development Work Experience