AscensionPHP Programming efficiency of a Elements
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( Brother LianPHPProgramming :the PHP manual says that Echo is a language structure, not a real function, so add a double quote to the Function. .
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 a client request ) , use $_server[ 'request_time' is better than time ().
the function replaces the regular expression to accomplish the same Function.
One and str_replace functions are faster than preg_replace functions, but strtr The efficiency of the function is four times times that of the str_replace 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 timesslower than incrementing a local variable .
incrementing an object property (for example: $this->prop++) is 3 slower than incrementing a local variable Times.
[php] 20 elements to improve PHP programming efficiency