PHP performance Optimization (ii)--php code writing habits Optimization _php Tutorial

Source: Internet
Author: User
The following summarizes the 18 PHP code can be done in writing optimization habits, in order to maximize the speed of the implementation of PHP code!

(1) uses static static Method 4 times times faster than normal method
(2) Echo output faster than print
(3) The connection character is used instead.
(4) Take out the maximum value before the loop, not the value in the loop
The right way
$max = count ($array);
for ($i =0; $i < $max; $i + +) {
echo $i;
}
The wrong way
for ($i =0; $i
echo $i;
}
(5) Use unset to release a given variable
(6) Includes and requires include file use full path
(7) Use STRNCASECMP, strpbrk and stripos instead of regex
(8) using switch instead of if Else statement
(9) Suppress error symbol @ Low performance
(10) Remember to close unwanted database connections at any time
(one) $row [' ID '] 7 times faster than $row [ID] Performance
(12) Adding a global variable is twice times slower than adding a local variable
(13) Use single quotes instead of double quotation marks to reference characters
(14) Use HTML 2-20 times faster than PHP scripts
(15) Use PHP cache to accelerate performance 25%-100%
(16) $++ $i slower than + +
(17) Do not overuse oop, moderate
(18) Use PHP built-in functions as much as possible

If there's a supplement, you're welcome to join.

http://www.bkjia.com/PHPjc/735171.html www.bkjia.com true http://www.bkjia.com/PHPjc/735171.html techarticle The following summarizes the 18 PHP code can be done in writing optimization habits, in order to maximize the speed of the implementation of PHP code! (1) using static Statics Method 4 times times faster than 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.