PHP Performance Optimization

Source: Internet
Author: User
Tags foreach php language variables php file

Although the PHP language function is powerful, but also needs the programmer to write the specification, creates the performance superior code program. Here we share PHP's performance optimization techniques.

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

For global variables, you should run out of unset ()

As little as possible to file operations, although the PHP file operation efficiency is not low;

Optimize the Select SQL statement and, if possible, minimize the INSERT, update operation (on update, I was bad batch) to achieve the purpose of PHP performance optimization;

Use PHP's internal functions as much as possible (but I've wasted the time and experience of writing a custom function in order to find a function that doesn't exist in PHP);

In the case of using file_get_contents instead of file, fopen, feof, fgets, and so on, try to use file_get_contents, because he is much more efficient! But pay attention to file_get_ Contents PHP version problem when opening a URL file;

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

Multidimensional arrays do not loop nesting assignments as much as possible;

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

foreach is more efficient and uses foreach instead of while and for loops as much as possible; (www.3lian.com)

Use single quotes instead of double quotes to quote strings for PHP performance optimization;

In multiple nested loops, if possible, the longest loop should be placed in the inner layer, and the shortest loop should be placed at the outer level, which can reduce the number of times the CPU spans the loop layer, thereby optimizing program performance

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.