PHP Code Optimization notes < one >

Source: Internet
Author: User
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.

  • 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.