Brother even PHP training teaches you 20 points to improve your efficiency

Source: Internet
Author: User
Tags switch case

Brother Lian PHP training teaches you to ascend An important point of efficiency

using single quotes instead of double quotation marks to contain strings can be faster. Because PHP searches for variables in a string surrounded by double quotes, single quotes do not, note: only echo can do this, it is a "function" that can take more than one string as a parameter( www.lampbrother.net PHP manual says that Echo is a language structure, not a real function, The function is added with double quotation marks .

1, if the method of the class can be defined as static, asfar as possible to define as static, it will increase the speed of nearly 4 times.

2. The speed of$row ['ID'] is $row [id] 7 times.

3.echo is faster than print and uses echo 's multiple parameters ( A comma instead of a period ) instead of a string connection, such as echo $str 1, $str 2.

4. To determine the maximum number of cycles beforeexecuting a for Loop, do not calculate the maximum value once per cycle, preferably using foreach instead.

5. Unregister those unused variables, especially large arrays, in order to free up memory.

6, try to avoid the use of __get,__set,__autoload.

7,require_once () expensive.

8,include files when possible to use absolute path, because it avoids PHP to include_path Files, it takes less time to parse the operating system path.

9.If you want to know when the script starts executing (the server side receives the client request ) , use $_server[' Request_time ' ] is better than time ().

the function replaces the regular expression to accomplish the same function.

Thestr_replace function is faster than the preg_replace function, but The efficiency of the STRTR function is Str_replace four times times the function.

If a string substitution function accepts an array or character as an argument, and the parameter length is not too long, consider writing an additional replacement code so that each pass argument is a character instead of just one line of code that accepts the array as a parameter for querying and replacing.

Use the Select Branch statement ( that is , switch case) better than using multiple if,else if statement.

using @ to mask error messages is extremely inefficient and extremely inefficient.

Open apache mod_deflate module, you can improve the browsing speed of the page.

The database connection should be turned off when used, do not use long connection.

error messages are costly.

increase the local variable in the method, the speed is the fastest. is almost equivalent to the speed at which local variables are called in the function.

incrementing a global variable is 2 times slower than incrementing a local variable .

incrementing an object property ( for example,$this->prop++) is 3 times slower than incrementing a local variable .


Brother even PHP training teaches you 20 points to improve your efficiency

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.