PHP, is the abbreviation of English Super Text preprocessing language hypertext preprocessor. PHP is an HTML embedded language, is a server-side implementation of embedded HTML document scripting language, language style has similar to C language, is widely used. Here's how to improve your PHP speed.
It is faster to include strings in single quotation marks than double quotes to contain strings. Because PHP will search for variables in a string surrounded by double quotes, single quotes will not, note: only echo can do this, it is a string can be used as a parameter of the "function" (in the PHP manual that echo is a language structure, not a real function, so the function with double quotation marks).
1, if the method of the class can be defined as static, as far as possible to define as static, it will increase the speed of nearly 4 times times.
2. The speed of $row [' ID '] is 7 times times that of $row[id].
3. Echo is faster than print, and uses Echo's multiple parameters (referring to commas instead of periods) instead of string connections, such as Echo $str 1, $str 2.
4. To determine the maximum number of cycles before executing 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, parsing the operating system path takes less time.
9. If you want to know when the script starts executing (that is, the server side receives the client request), use $_server[' request_time '] better than time ().
10, function instead of regular expression to complete the same function.
11, the Str_replace function is faster than the Preg_replace function, but the efficiency of the STRTR function is four times times the Str_replace function.
12, if a string substitution function, can accept an array or character as a parameter, and the parameter length is not too long, then you can consider an extra piece of replacement code, so that each pass argument is a character, rather than write a line of code to accept the array as the query and replace parameters.
13. Use the Select Branch statement (that is, switch case) better than using multiple if,else if statements.
14. Masking error messages with @ is extremely inefficient and extremely inefficient.
15, open the Apache mod_deflate module, can improve the browsing speed of the page.
16, the database connection should be turned off when used, do not use long connection.
17. Error messages are costly.
18, increment the local variable in the method, the speed is the quickest. is almost equivalent to the speed at which local variables are called in the function.
19, incrementing a global variable is twice times slower than incrementing a local variable.
20, incrementing an object property (such as: $this->prop++) is 3 times times slower than incrementing a local variable.
One of the advantages of PHP is that it is fast and is sufficient for general website applications. However, if the site traffic is high, with narrow or other factors to make the server performance bottlenecks, the speed is our first thought. I hope this article will be of help to you.
http://www.bkjia.com/PHPjc/445803.html www.bkjia.com true http://www.bkjia.com/PHPjc/445803.html techarticle PHP, is the abbreviation of English Super Text preprocessing language hypertext preprocessor. PHP is an HTML embedded language, is a server-side execution of embedded HTML document script language, ...