PHP performs slow optimization of interface execution

Source: Internet
Author: User

The reason why PHP is slow to perform inefficient optimization of the interface can cause a lot of reasons for inefficient execution
    • From the code level, the code quality is low, and execution efficiency can have a significant impact.
    • From the hardware side, the server configuration is low, the server configuration is the foundation, this run is certainly slow.
    • From the data volume aspect, the query data quantity is too large, the SQL statement is too complex, the execution is slow.
Server

From the configuration to do the promotion, the overall performance of the system is quite obvious, there is no good doubt, as long as there is strength, nature can be more in this respect to do a promotion.

Data query

The optimization of this query, involving the optimization of SQL, or to the optimization of the database, there are a few simple optimization scenarios.

    • SQL optimization, proper use of linked list queries, use of joins to replace subqueries, general large tables and multi-table situations avoid the use of joins, in which case the use of joins is not the effect of simplifying the query.
    • SQL optimization, query table data when the exact field name to query, avoid unnecessary field query.
    • SQL optimizations, using the primary foreign key and index appropriately.
    • SQL optimization, use in query appropriately, use fuzzy query appropriately.

      ··········
    • Database optimization, the field uses a reasonable field type, and another way to improve efficiency is to set the field as notnull as possible, to avoid wasted space.
    • Database optimization, reasonable design table structure.

      ··········
Code optimization

The code optimization is also individual, each person may be coding habits and styles, for improving code performance have their own views, the following is part of my view.

    • foreach is reasonable to use, as little as possible in the loop to apply the cycle, in the case of excessive number of cycles, very consumption performance.
    • In the loop, try to avoid the data operation, especially the query operation, in the case of excessive number of cycles, multiple call efficiency is very low, can get data and then splicing.
    • Similarly, in a loop, you avoid multiple fetches of the configuration, and the invocation of the time () function method, which can be reused for a single declaration.
    • In PHP, single and double quotation marks are different, as a customary string I use single quotes, because it does not need to compile, for efficiency, may not be the difference in size, may be a little
    • Rational use of functions in PHP, like array functions is very rich, to make full use of, generally do not do his own support of the function method
    • You can use the concept of the dictionary to store the array in a new index, which I used very often in the reorganization of the data.
    • Based on the scenario, reasonable use of the cache can reduce duplication of data query, improve efficiency
    • Reasonable Split function, such as a list query, and with details to view, can be split here into two interface implementation, when needed to obtain data, reduce the waste of resources.
      ··········

PHP performs slow optimization of interface execution

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.