Home  >  Article  >  Backend Development  >  PHP performance optimization (2) - PHP code writing habits optimization_PHP tutorial

PHP performance optimization (2) - PHP code writing habits optimization_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:37:41726browse

The following summarizes 18 optimization habits that can be done when writing php code to maximize the speed of PHP code execution!

(1) Using static static methods is 4 times faster than ordinary methods
(2) echo output is faster than print
(3) Use , instead of .
for connection characters (4) Take the maximum value before looping instead of taking the value inside the loop
The correct way
        $max = count($array);
for ($i=0;$i<$max;$i++) {
echo $i;
}
Wrong method
for ($i=0;$i echo $i;
}
(5) Use unset to release the given variable
(6) Includes and requires include files using full paths
(7) Use strncasecmp, strpbrk and stripos instead of regex
(8) Use switch instead of if else statement
(9) The performance of suppressing the error symbol @ is very low
(10) Remember to close unnecessary database connections at any time
(11) $row['id'] is 7 times faster than $row[id]
(12) Adding a global variable is 2 times slower than adding a local variable
(13) Use single quotes instead of double quotes to quote the character
(14) Using HTML is 2-20 times faster than PHP scripts
(15) Using PHP cache can speed up performance by 25%-100%
(16)$++ is slower than ++$i
(17) Don’t overuse OOP, only use it in moderation
(18) Try to use PHP built-in functions

If you have anything to add, you are welcome to join

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/735171.htmlTechArticleThe following summarizes 18 optimization habits that can be done in PHP code writing to ensure the maximum execution of PHP code Quick sex! (1) Using static static methods is 4 times faster than ordinary methods (...
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