This article provides a detailed analysis of php code writing habits optimization. For more information, see (1) use static methods four times faster than normal methods.
(2) echo output is faster than print
(3) use the connection character instead.
(4) take the maximum value before the loop, instead of taking the value in the loop.
Correct Method $ Max = count ($ array );
For ($ I = 0; $ I <$ max; $ I ++ ){
Echo $ I;
}
Incorrect method For ($ I = 0; $ I Echo $ I;
}
(5) use unset to release a given variable
(6) use the complete path for the files contained in includes and requires
(7) replace regex with strncasecmp, strpbrk, and stripos
(8) replace if else statement with switch
(9) suppress error characters @ low performance
(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 twice slower than adding a local variable.
(13) use single quotes instead of double quotes to reference characters
(14) using HTML is 2-20 times faster than PHP scripts
(15) PHP Cache accelerates performance by 25%-100%
(16) $ ++ is slower than ++ $ I
(17) do not over-use OOP.
(18) use PHP built-in functions whenever possible
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service