PHP system performance optimization principles good System design

Source: Internet
Author: User
Some people may disagree with the order of the second and third places, because one of my friends mentioned it, but after a while, he also agreed that maintenance is more important than performance. It can only be said that it is my personal experience, and there is no way to prove the process step by step like a mathematical formula.

Here we record the principles and steps that I think should be followed when doing optimization work. they are not specific optimization methods (there are many optimization methods for google ).

When it comes to performance optimization, we will hear double quotation marks, single quotation marks, and third signs. I think if you follow this, it will be a little rounded down.

Before optimization, let's talk about my understanding of the system design goals.

  • First: runable. This is the most important and there should be no objection.
  • Second: maintenance. Make sure that the design can be maintained by others or by yourself after a period of time.
  • Third: Performance and other

Some people may disagree with the order of the second and third places, because one of my friends mentioned it, but after a while, he also agreed that maintenance is more important than performance. It can only be said that it is my personal experience, and there is no way to prove the process step by step as evidenced by mathematical formulas.

Optimization sequence

The performance of the PHP program is described here.

First, good System design

I can assure that PHP will not become a performance bottleneck in most cases for Web systems. The bottleneck is often caused by system design and business logic sorting problems. If the system design is unreasonable, it would be useless to replace all the double quotes into single quotes.

For example, we didn't plan much cache access in the initial stage of a system design. the number of cache accesses in a single request is too large, and it is worse to access the database quickly. (Therefore, the cache should be carefully designed from the very beginning like a relational table)

Then: code and script

This step is also critical. In practice, we often encounter two types of problems:

  • SQL operations are nested in the loop.
  • Too many scripts, too large.

The second type of problems are often ignored. Not long ago, when we visited an internal service (dependent on the sdk provided by it), the performance could not be improved. Finally, I merged all the classes in the sdk into a file, improving the performance by 10% instantly. This is a problem with too many scripts. we have solved it, but we have not solved the problem of too many scripts, because even after merging, there are thousands of lines of code, the performance report presented by xhprof is still a large box.

If the script is too large, you may not be able to easily notice the following suggestion: change the controller/action design to the action design to avoid the emergence of the ultra-large controller and thus improve some performance.

For single quotation marks and double quotation marks, we recommend that you keep them uniform in the project. Either use one pair separately or use double quotation marks in a uniform manner, which will not be the bottleneck of performance.

I suggest that you consider how to use the third and double equal signs in terms of program logic correctness.

Speaking of scripts, I have a long question: Is there a need for smarty? Isn't the native template syntax of php better?

Finally, focus on PHP itself

If the system performance is still unsatisfactory, consider the server environment itself.

  • If php version is less than 5.4, upgrade it if you can.
  • Some stable and common logics are written as PHP extensions. For example, the program framework (@ see yaf) and pure ip database access.

After so many years of web development, I have always believed that PHP itself is difficult to become a performance bottleneck.

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.