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...