PHP development experience 1. solid basic PHP knowledge, functions, constants, etc. try to use built-in methods to solve the problem (because personal writing is often less efficient than built-in methods );
II. implement as few functions as possible (because PHP is actually executed to process our code into the underlying language for machine execution. if there are many codes, the converted content is naturally time-consuming );
3. during optimization, you can test your own code through the stress test AB. after the code is optimized, stress test the efficiency again;
4. use less @ characters;
5. use the unset () function to unregister and release the variable;
6. less regular expressions, a double-edged sword;
7. avoid repeating in the for loop condition;
8. the key value of the array must be a string with quotation marks as the key value. why?
When $ arr = array ("key" => "hehe"); $ arr ["key"] is correct and improves efficiency
$ Arr [key] is not enclosed in quotation marks, because keys are not enclosed in quotation marks during PHP execution.
At this time, he will check whether the key is a constant. if the error mechanism is enabled, the system will prompt notice.
No key is found. If quotation marks are added, PHP will directly enter the $ arr array to find the key value as the key,
Relatively efficient
9. external factors affecting PHP performance include:
The inspiration from this is that when a website is slow, it may not be because of slow PHP performance, network problems, or hardware problems; as an architect, the problem cannot be solved by program optimization!
10. reading memory content is less efficient than reading database content. Therefore, websites with high traffic speed often cache data to the memory using distributed caches such as memcache and redis, then, read data with the memory;
11. XHPorf (derived from Facebook to test the PHP performance analysis tool) can be used to test the process of visiting websites, and can be quickly found in the red area of the process icon, which is time-consuming, optimize the method;
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.