PHP program optimization. png
-
echo is faster than print.
-
Use Echo's multiple arguments instead of string joins.
-
To determine the maximum number of loops before executing a for loop, do not calculate the maximum value once per loop, preferably using foreach instead.
-
For the global variable, it should be unset () off.
-
Using single quotes instead of double quotation marks to contain strings can be faster. Because PHP searches for a variable in a string surrounded by double quotes, the single quotation mark does not.
-
function to perform the same function instead of a regular expression.
-
When the variable $i is incremented or decremented, $i + + will be slower $i than the + +. This difference is unique to PHP, not for other languages, + + $i faster because it requires only 3 instructions (opcodes), $i + + requires 4 instructions. The post increment actually produces a temporary variable, which is then incremented. The predecessor increment is incremented directly on the original value.
-
Using the Select Branch statement (switch case) is better than using multiple if,else if statements.
-
Debug PHP code with Var_dump. If you are looking for PHP debugging techniques, I have to say that var_dump should be the target you are looking for, and that this command will meet all your needs in terms of displaying PHP information, and most of the debugging code is related to getting the values in PHP.
-
The full path is used when the file is included, and less time is required to resolve the operating system path.
-
It's a bad idea to create global values at will, but sometimes it does. Using global values for database tables or database connection information is a good idea, but do not use global values frequently in your PHP code. In addition, a better approach is to put your global variables in a config.php file.
-
If you want to know when the script starts executing, use $_server[' request_time '] better than time ().
-
Open the Apache mod_deflate module.
-
Using @ To mask error messages is very inefficient.
-
Try to use a lot of PHP built-in functions.
-
Incrementing a non-predefined local variable is 9 to 10 times times slower than incrementing one of the pre-defined local variables.
-
A method in a derived class runs faster than the same method that is defined in the base class.
-
Defining only a local variable without calling it in the function also slows down the speed (which is equivalent to incrementing a local variable)
-
Apache Parsing a PHP script is 2 to 10 times times slower than parsing a static HTML page. Use static HTML pages as much as possible and use fewer scripts.
-
As mentioned earlier, 99% of the most important parts of any PHP Web site may be databases. Therefore, you need to be very familiar with how to use SQL correctly, learn related tables and more advanced database technologies.
-
Calling an empty function with one parameter takes a time equivalent to performing a local variable increment operation of 7 to 8 times.
-
When you manipulate a string and need to verify that its length satisfies a certain requirement, you will of course use the strlen () function. This function executes quite quickly because it does not do any calculations and only returns the length of the known string stored in the Zval structure (the built-in data structure of C, used to store PHP variables).
-
Not all cases must use object-oriented development, object-oriented tends to be expensive, and each method and object invocation consumes a lot of memory.
-
Unless the script can be cached, it will be recompiled every time it is called. Introducing a set of PHP caching mechanisms can typically improve performance by 25% to 100% to eliminate compilation overhead.
Finally, let's remind you of the things you should be aware of when optimizing your code: