Home  >  Article  >  Backend Development  >  Tips Sharing PHP Performance Optimization_PHP Tutorial

Tips Sharing PHP Performance Optimization_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:34:28768browse

"Replace i=i+1 with i+=1. It conforms to the habits of c/c++ and is more efficient";

For global Variables should be unset()ed when used up

Do as little file operations as possible, although PHP’s file operations are not inefficient;

Optimize Select SQL statements, where possible Conduct Insert and Update operations as little as possible (I was criticized for updating) to achieve the purpose of optimizing PHP performance;

Use PHP internal functions as much as possible (but I just wanted to find one that does not exist in PHP) function, wasting time that could have been spent writing a custom function, a matter of experience!);

When file_get_contents can be used instead of file, fopen, feof, fgets and other series of methods, try to use file_get_contents , because it is much more efficient! But please pay attention to the PHP version problem of file_get_contents when opening a URL file;

Do not declare variables inside the loop, especially large variables: objects (this seems to be not only required in PHP Pay attention to the problem?);

Try not to nest nested assignments in multi-dimensional arrays;

Don’t use regular expressions when you can use PHP’s internal string manipulation functions;

Foreach is more efficient, try to use foreach instead of while and for loops;

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

In multiple nested loops , if possible, the longest loop should be placed in the inner layer and the shortest loop in the outer layer, so as to reduce the number of times the CPU crosses the loop layer and optimize program performance.


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445982.htmlTechArticleReplace i=i+1 with i+=1. It conforms to the habits of c/c++ and is highly efficient; for global variables, they should be unset()ed after use and as few file operations as possible, although PHP's file operation efficiency is not low; Excellent...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn