Pick up the article
3. Optimize points: Use as few magical functions as possible
Scenario Description: PHP provides a magic function that is poorly performing
Why is it? In order to save PHP programmers a lot of trouble, the PHP language to do many
Good approach: Avoid using PHP magic functions as much as possible, and weigh the pros and cons when you need to use them.
4. Optimization point: Error suppressor that generates additional overhead
Case Description: PHP provides error suppressors just for the convenience of "lazy people"
The actual logic of the @ symbol: Before the code starts, after the end, add opcode, ignoring the error.
Good advice: Try not to use the @ error suppressor
5. Optimize points: use memory reasonably
Case Description: PHP has a guaranteed memory recovery mechanism, but please also use memory carefully.
Good advice: Use unset () even if you are releasing unused memory. (Note: unset will not be logged out of the situation)
6. Optimize points: Use regular expressions as little as possible
Case Description: The retrospective overhead of regular expressions is large, and if the basis of regular expressions is not good, use caution.
Good advice: Use string processing functions to implement the same logic.
7. Optimize points: Avoid doing operations within the loop
Description: The calculation in the loop will be repeated.
code example:
Wrong way, each cycle to calculate the length of $str $str = "Hello World"; for ($i =0; $i <strlen ($STR); $i + +) {//Here is the logical}//correct practice, only one length can be calculated $str = ' Hello world ', $len = strlen ($STR); for ($i =0; $i < $len; $i + +) {//This is logic}
8. Optimize points: Reduce compute-intensive business
Scenario Description: PHP is not suitable for intensive computing scenarios. PHP features determine that PHP is not suitable for large data-volume operations.
PHP application scenario, suitable for connecting webserver and backend services, UI rendering.
9. Optimize points: Be sure to use quoted strings as key values
Case Description: PHP will handle unquoted key values as constants, resulting in the overhead of finding constants.
Good advice: Use quote key values strictly.
Small ant learning php performance Optimization (2)--php language-level performance optimization