PHP code optimization excerpt <一>
1. If a method can be statically declared, the speed can be increased to 4 times times.
2. Echo is faster than print and uses Echo's multiple parameters instead of string connections.
3. Determine the maximum number of loops before executing the For loop, and do not calculate the maximum value once per loop. for ($i =0; $i
<>
4. Unregister those unused variables, especially large arrays, in order to free up memory.
5. Try to avoid using __get __set __autoload.
6. Require_once () is costly.
7. When you include a file with a full path, less time is required to resolve the operating system path.
8. If you want to know when the script starts executing, $_server[' request_time ' is better than time ()
9. function instead of regular expression to complete the same function.
The efficiency of the 10.STRTR function is 4 times times higher than the efficiency of the str_replace.
11. Using the Select Branch statement switch case is better than using multiple If,elseif
[Email protected]
13. When the database connection is completed, close it promptly.
$val [' id '] is much more efficient than $val[id.
15. Incrementing a local variable is much slower than incrementing a local variable, and incrementing an object property ($this->prop++) is much slower than incrementing a local variable.
16. Define only one local variable two not calling it in the function will also slow down the speed. The method invocation is independent of the number of methods defined in the class.
17. A method in a derived class runs faster than the same method defined in the base class.
18. The efficiency of single quotes is faster than double quotes, because PHP searches for variables in a string surrounded by double quotes.
19.Apache Parsing a PHP script is twice times slower than parsing an HTML page by 10 times times, using static HTML scripts as much as possible.