Php performance optimization (II) -- php code writing habits Optimization _ PHP Tutorial

Source: Internet
Author: User
Php performance optimization (2)-php code writing habits optimization. The following summarizes the optimization habits that can be done in 18 php code writing to maximize the speed of php code execution! (1) the static method is four times faster than the normal method (The following summarizes the optimization habits that can be done in 18 php code writing to maximize the speed of php code execution!

(1) the static method is four times faster than the normal method.
(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

If you have any additional information, please join us.

Optimization habits that can be done in the coding of the php code to maximize the speed of php code execution! (1) the static method is four times faster than the normal method (...

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.