PHP Performance Efficiency optimization

Source: Internet
Author: User

Recently in the company while writing a PHP program, because the company's operating efficiency requirements of the program is very high, but also a novice, the first attention to the efficiency of the program is very important, here on the combination of some information on the web, summed up under the PHP program efficiency optimization of some strategies:

1. When you can use file_get_contents instead of file, fopen, feof, Fgets and other series of methods, as far as possible with file_get_contents, because his efficiency is much higher! But be aware of the PHP version of file_get_contents when you open a URL file

2. As little as possible file operation, although the PHP file operation efficiency is not low;

3. Optimize select SQL statements, as little as possible in the case of INSERT, update operations (on the update, I was a bad batch);

4. Use PHP internal function as much as possible (but I am looking for a function that does not exist in PHP, wasting the time that can write a custom function, experience problem!) );

5. Do not declare variables inside the loop, especially large variables: objects (this seems to be not just a matter of note in PHP)? );

6. Multidimensional arrays as far as possible not to cycle nested assignment;

7. Do not use regular expressions when you can use PHP internal string manipulation functions;

8.foreach more efficient, try to use foreach instead of while and for loops;

9. Use single quotes instead of double quotes to quote strings;

10. "Replace I=i+1 with I+=1." In line with C + + habits, efficiency is also high ";

11. For global variables, you should unset () out

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.