This article is mainly to share with you the PHP performance optimization tips, hoping to help you write better PHP code.
(1) foreach is more efficient, instead of using foreach as a while and for loop;
(2) Inside the loop do not declare variables, especially objects such variables;
(3) in multiple nested loops, if possible, the longest cycle should be placed in the inner layer, the shortest loop in the outer layers, thereby reducing the number of cycles across the CPU, optimize program performance;
(4) Use single quotation marks instead of double quotation marks to reference strings for PHP performance optimization;
(5) Replace i=i+1 with I+=1. In line with the C + + habit, the efficiency is high;
(6) Optimization of the Select SQL statement, as far as possible in the case of INSERT, update operation, to achieve the purpose of PHP performance optimization;
(7) As far as possible to file operations, although the PHP file operation efficiency is not low;
(8) Use PHP intrinsics as much as possible;
(9) Do not use regular expressions in cases where PHP internal string manipulation functions are possible;
(ten) feof, Fgets, fopen, in the case can be used file_get_contents alternative file, series of methods, as far as possible to use file_get_contents, because it is much more efficient. But be aware of the PHP version of file_get_contents when opening a URL file.