PHP performance optimization tips for sharing

Source: Internet
Author: User
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.

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.