In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article is about what PHP code optimization techniques are about. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
1. Echo is faster than print.
2. Use multiple parameters of echo instead of string concatenation.
3. Determine the maximum number of cycles before executing the for loop. Do not calculate the maximum value every time. It is best to use foreach instead.
4. For the global variable, unset () should be dropped as soon as it is finished.
5. It is faster to use single quotation marks instead of double quotation marks to include strings. Because PHP searches for variables in strings enclosed in double quotes, single quotes do not.
6. Function performs the same function instead of regular expression.
7. When executing the increment or decrement of the variable $I, $I will be slower than + + $I. This difference is unique to PHP and does not apply to other languages. + $I is faster because it requires only three instructions (opcodes) and $iTunes + requires four instructions. The post increment actually produces a temporary variable, which is then incremented. The pre-increment increases directly on the original value.
8. It is better to use a selective branch statement (switch case) than to use multiple if,else if statements.
9. Use var_dump to debug the PHP source code. If you are looking for php debugging technology, I must say that var_dump should be the target you are looking for, this command can meet all your needs in displaying php information, and most of the debugging code has to do with getting values in PHP.
10. Using the full path when including files will take less time to resolve the operating system path.
11. It is a bad practice to create global values easily, but sometimes it is necessary to do so. It's a good idea to use global values for database tables or database connection information, but don't use global values frequently in your PHP code. In addition, a better approach is to store your global variables in a config.php file.
12. If you want to know when the script starts to execute, using $_ SERVER ['REQUEST_TIME'] is better than time ().
13. Open the mod_deflate module of apache.
14. The practice of blocking error messages with @ is very inefficient.
15. Try to use a large number of PHP built-in functions.
Incrementing an undefined local variable is 9 to 10 times slower than incrementing a predefined local variable.
Methods in derived classes run faster than the same methods defined in the base class.
18. Defining a local variable without calling it in the function also slows down (to the extent equivalent to incrementing a local variable)
19. Apache parses a PHP script 2 to 10 times slower than a static HTML page. Try to use more static HTML pages and fewer scripts.
20. As mentioned earlier, the most important part of any php site is likely to be a database. Therefore, you need to be very familiar with how to use sql correctly, learn associative tables and more advanced database techniques.
21. Calling an empty function with one parameter takes the same time as performing 7 to 8 local variable increments.
22. When you manipulate a string and need to verify that its length meets a certain requirement, you will naturally use the strlen () function. This function is fairly fast because it doesn't do any calculations and only returns the known string length stored in the zval structure (C's built-in data structure for storing PHP variables).
23. Not all cases must use object-oriented development. Object-oriented is often very expensive, and each method and object call consumes a lot of memory.
Unless the script can be cached, it will be recompiled each time it is called. The introduction of a PHP caching mechanism can typically improve performance by 25 to 100 percent, eliminating compilation overhead.
Thank you for reading! This is the end of this article on "what are the PHP code optimization skills?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.