PHP skills: optimize dynamic web skills 12 skills for PHP programs

Source: Internet
Author: User
If a function can be declared as static, then it uses static, and the speed is a factor of improvement 4. when using include and require, try to use the full path to reduce the time spent on solving the OS path. if you need to know the start time of a script, using $ _ SERVER ['request _ time'] is better than using TIME (). 1. If a method can be static, declare it static. speed improvement is by a factor of 4.
1. if a function can be declared as static, the static function is used, and the speed is a factor for improvement. 4.

2. # Avoid magic like _ get, _ set, _ autoload
2. avoid applying magic functions such as _ get, _ set, and _ autoload.

3. require_once () is expensive
3. require_once () is very expensive.

4. Use full paths in between DES and requires, less time spent on resolving the OS paths.
4. when using include and require, try to use the full path to reduce the time spent on solving the OS path.

5. If you need to find out the time when the scr when pt started executing, $ _ SERVER ['request _ time'] is preferred to TIME ()
5. if you need to know the start TIME of a script, it is better to use $ _ SERVER ['request _ time'] than to use time ().


6. See if you can use strncasecmp, strpbrk and stripos instead of regex
6. if strncasecmp, strpbrk and stripos can be used, do not use regular expressions.

7. preg_replace is faster than str_replace, but strtr is faster than preg_replace by a factor of 4
7. preg_replace is faster than str_replace, but strtr is faster than preg_replace.

8. If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
Some functions, such as string replacement functions, receive arrays and a single character as parameters. if your parameter list is not very long, consider writing redundant replacement statements to transmit one character each time, the array received by a line of code is used as the search and Replacement parameter.

9. Error suppression with @ is very slow.
9. disabling the error output symbol @ is very slow.

10. $ row ['id'] is 7 times faster than $ row [id]
10. $ row ['id'] is 7 times faster than $ row [id]

11. Error messages are expensive
11. error messages are very expensive.

12. Do not use functions inside of for loop, such as for ($ x = 0; $ x <count ($ array); $ x) The count () function gets

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.