Php performance efficiency optimization _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Php performance efficiency is optimized. Php performance efficiency optimization recently, I learned to write PHP programs at the company side. as the company has high requirements on program running efficiency, I am a newbie, at the beginning, pay attention to the program efficiency. php performance efficiency is optimized.
Recently, I learned to write PHP programs on my own. because the company has high requirements on program running efficiency and I am a newbie, it is very important to pay attention to the program efficiency at the beginning, here we will summarize some strategies for optimizing the efficiency of php programs based on some online materials:

1. when file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, try to use file_get_contents, because its efficiency is much higher! Note the PHP version of file_get_contents when opening a URL file.

2. perform as few file operations as possible, although PHP file operations are not efficient;

3. optimize Select SQL statements and perform Insert and Update operations as little as possible (I have been maliciously approved in update );

4. try to use PHP internal functions as much as possible (but in order to find a function that does not exist in PHP, it is a waste of time to write a user-defined function, experience problems !);

5. do not declare variables inside the loop, especially big variables: objects (doesn't it seem to be a concern in PHP ?);

6. do not use nested values for multi-dimensional arrays;

7. do not use regular expressions when you can use PHP internal strings to operate functions;

8. foreach is more efficient. use foreach instead of the while and for loops;

9. use single quotes instead of double quotes to reference strings;

10. "replace I = I + 1 with I + = 1. In line with the c/c ++ habits, high efficiency ";

11. unset () should be used up for global variables

Parse recently learned to write PHP programs at the company side. because the company has high requirements on program running efficiency, and he is a newbie, he should pay attention to the program efficiency at the beginning...

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.