In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article focuses on "how to improve the efficiency of PHP programming", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how PHP can improve the efficiency of programming.
1. If you can define the method of a class as static, try to define it as static, which will be nearly 4 times faster.
2. The speed of $row ['id'] is seven times that of $row [id].
3. Echo is faster than print and uses multiple parameters of echo instead of string concatenation, such as echo $str1,$str2.
4. 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.
5. Log out unused variables, especially large arrays, in order to free memory.
6. Avoid using _ _ get,__set,__autoload as much as possible.
7. Require_once () is expensive.
8. Include files use absolute paths as far as possible, because it avoids the speed at which PHP looks for files in include_path, and it takes less time to parse the operating system path.
9. If you want to know when the script starts to execute, using $_ SERVER ['REQUEST_TIME'] is better than time ().
10. The function performs the same function instead of the regular expression. The regular efficiency is generally lower than the function.
11. The str_replace function is faster than the preg_replace function, but the strtr function is four times more efficient than the str_replace function.
12. If a string replacement function accepts arrays or characters as parameters, and the parameter length is not too long, you can consider writing an additional replacement code so that each passing parameter is one character. Instead of just writing one line of code, you can accept an array as a query and replacement parameter.
13. It is better to use a selective branch statement (switch case) than to use multiple if,else if statements.
14. The practice of blocking error messages with @ is very inefficient, extremely inefficient.
15. Open the mod_deflate module of apache to improve the browsing speed of the web page.
16. The database connection should be turned off when it is finished, and do not use a long connection.
17. Error messages are expensive.
18. It is the fastest to increment local variables in the method. It is almost as fast as calling a local variable in a function.
19. Incrementing a global variable is twice as slow as increasing a local variable.
20. Incrementing an object property (such as $this- > prop++) is 3 times slower than incrementing a local variable.
21. Incrementing an undefined local variable is 9 to 10 times slower than incrementing a predefined local variable.
22. Defining a local variable without calling it in the function also slows down (to the extent equivalent to incrementing a local variable). PHP will probably check to see if there are global variables.
23. Use single quotation marks instead of double quotation marks to include strings
At this point, I believe you have a deeper understanding of "PHP how to improve the efficiency of programming". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.