PHP performance optimization-PHP Tutorial

Source: Internet
Author: User
PHP performance optimization. Despite its powerful functionality, PHP requires programmers to write specifications to create code programs with superior performance. Next we will share with you the PHP performance optimization skills. "Although PHP is powerful, it also requires programmers to write specifications to create code programs with superior performance. Next we will share with you the PHP performance optimization skills.

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

For global variables, unset () should be used up

Perform as few file operations as possible, although PHP file operations are not efficient;

Optimize the Select SQL statement. if possible, perform Insert and Update operations as little as possible (on update, I have been maliciously approved) to optimize the PHP performance;

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 and experience to write a custom function !);

When file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, use file_get_contents as much as possible because of its high efficiency! Note the PHP version of file_get_contents when opening a URL file;

Do not declare variables inside the loop, especially big variables: objects (this does not seem to be a concern in PHP ?);

Multi-dimensional arrays should not be nested repeatedly;

Do not use regular expressions when you can use PHP internal strings to operate functions;

Foreach is more efficient. use foreach instead of the while and for loops. (www.bkjia.com)

Use single quotes instead of double quotes to reference strings to optimize PHP performance;

In multiple nested loops, if possible, the longest loop should be placed on the inner layer, and the shortest loop should be placed on the outer layer. This can reduce the number of times that the cpu switches across the loop layer, thus optimizing program performance.

Bytes. Next we will share with you the PHP performance optimization skills. "Use...

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.