PHP code optimization tips big check, php tips big check _ PHP Tutorial

Source: Internet
Author: User
Tags php website switch case how to use sql
Check PHP code optimization skills and php skills. PHP code optimization tips: check php skills. the purpose of PHP optimization is to get the fastest running speed and the most easily maintained code at the minimum cost. This article provides you with comprehensive PHP code optimization tips for big inventory, php skills for big inventory

The goal of PHP optimization is to get the fastest running speed and the most easily maintained code at the lowest cost. This article provides you with comprehensive optimization skills.

1. echo is faster than print.

2. use multiple echo parameters to replace string connection.

3. determine the maximum number of cycles before executing the for loop. do not calculate the maximum value for each loop. use foreach instead.

4. for global variables, unset () should be used up.

5. replace double quotation marks with single quotes to include strings. this will be faster. Because PHP searches for variables in strings enclosed by double quotation marks, but not in single quotes.

6. functions use the same functions instead of regular expressions.

7. when the execution variable $ I increments or decreases, $ I ++ is slower than ++ $ I. This difference is exclusive to PHP and does not apply to other languages. ++ $ I is faster because it only requires three commands (opcodes) and $ I ++ requires four commands. In fact, a temporary variable is generated in post-increment mode, which is then incremented. The pre-increment directly increases on the original value.

8. the switch case statement is better than the if and else if statements.

9. use var_dump to Debug PHP code. If you are looking for php debugging technology, I must say that var_dump should be your target. this command can meet all your needs in displaying php information, most of the debugging code is related to obtaining the value in PHP.

10. if you use the full path when the file is included, it takes less time to parse the operating system path.

11. it is a bad practice to easily create a global value, but sometimes the actual situation does need to be done again. It is a good idea to use global values for database tables or database connection information, but do not use global values frequently in your PHP code. In addition, a better way is to store your global variables in a config. php file.

12. if you want to know the TIME when the script starts to be executed, use $ _ SERVER ['request _ time'] instead of time ().

13. open the mod_deflate module of apache.

14. blocking error messages with @ is very inefficient.

15. try to use a large number of PHP built-in functions.

16. increasing an unspecified local variable is 9 to 10 times slower than increasing a predefined local variable.

17. the method in the derived class runs faster than the same method defined in the base class.

18. defining only one local variable without calling it in the function also slows down (to the extent that it is equivalent to increasing one local variable)

19. Apache parses a PHP script two to ten times slower than parsing a static HTML page. Use static HTML pages and less scripts as much as possible.

20. as mentioned before, 99% of the most important parts of any php website may be databases. Therefore, you need to be familiar with how to use SQL correctly and learn to associate tables and more advanced database technologies.

21. calling an empty function with a parameter takes seven to eight times to increment local variables.

22. when operating on a string and checking whether its length meets certain requirements, you use the strlen () function. This function is executed quite quickly because it does not perform any calculations and only returns the known string length stored in the zval structure (the built-in data structure of C, used to store PHP variables.

23. not all situations require the use of object-oriented development. object-oriented development usually consumes a lot of memory for each method and object call.

24. unless the script can be cached, it will be re-compiled every time it is called. The introduction of a PHP Cache mechanism can generally improve the performance by 25% to 100%, so as to avoid compilation overhead.

The goal of optimize the PHP runtime is to get the fastest running speed and the most easily maintained code at the lowest cost. This article provides you with comprehensive optimization...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.