PHP basic tutorial discusses some php programming performance optimization summary





Brothers PHP training

Xiaobian is doing performance optimization of php programs recently, and some things found after testing are recorded first for later use.

  First of all, for some slow-response operations or pages to be tracked and processed, you can use webGrind to see where the main problem lies.

  Second , for the optimization of methods, one is to view the optimization of the statements called in the method, and the other is for the algorithm of the method itself. The location of the called method is also very important. Generally speaking, calling the method in other files is not as fast as calling the method in this page. If it is a frequently used method and the calling process is time-consuming, for performance considerations , you can port this method to this page.

  The optimization of the statement in the method body includes the optimization of the method called. For example, using the statement $a=='' is not as good as using $a.length()==0, the more optimized is empty($a), try to use it when writing code The method with the best performance, such as: preg_replace is not as good as str_replace, str_replace is not as good as strtr, use strtr for equal-length replacement, and use str_replace

  loop for unequal-length replacement. Try to use foreach instead of for

  to minimize the number of requests to the server, which should be compressed from javascript , css compression, the picture should be in png format as much as possible, and it is best to use the image segmentation css method to load the picture.

  Enable site-wide code compression and

  enable Consider using some php binary code optimization tools, such as xcache, to optimize the background code.

  Consider using some cutting-edge technologies such as memcache to store some small strings, which is better than file caching. Many, you can also consider using redias and the like.

  If you can not refer to external files in the program, don't refer to it. Referencing files also takes a certain amount of time. Refer to other files as little as possible. In addition, for some branch statements, if the statements that are useless to this branch must not be accessed by this branch. to, it's a waste.

  If you really can't change it, you can consider optimizing the algorithm and framework.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326475666&siteId=291194637