Three elements to improve the efficiency of PHP programming
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 even php programming :the PHP manual says that Echo is a language structure, not a real function, so the function is added 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,$row ['ID'] speed is $row [id] of the 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 as far as possible to use absolute path, because it avoids PHP to include_path to find the speed of the file, It takes less time to resolve 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 .
20 elements to improve PHP programming efficiency