How does php and mysql increase efficiency across servers?

Source: Internet
Author: User
How does php and mysql increase efficiency across servers? I developed an APP. when the server uses LAMP, php, and mysql on a server, the app's response speed is okay.

However, considering that php and mysql may need to be deployed on different servers separately in the future, I tested this method and found that the app's response was slow, and each response took about 10 seconds.

I analyzed my php implementation code and found that php and mysql interact hundreds of times in an app request. although each request requires a little time, it adds up to hundreds of requests. In fact, the database itself does not need much time to query, and it is estimated that it will be spent on the cross-server network latency of php and msysql.

How can we improve efficiency in cross-server scenarios? I think of two methods: 1. improve the network transmission performance of php and mysql servers (I am using a wireless LAN at home, if it is a wired LAN or a better Gigabit LAN, the latency will be very small ?) 2. php does not need to implement its own business logic, send the request to mysql, and then mysql uses the stored procedure for implementation, so that only one interaction is required between php and mysql, it should be able to solve the problem of network transmission latency.

I don't have much experience in developing php. please help me to see how it works or there are other solutions.

Thank you!


Reply to discussion (solution)

1. use persistent connection to connect to the database
2. read the query results locally at one time (mysqli_result: store_result, pdo: fetchall)

Thank you!

These two methods can improve the performance.

However, in some cases, it is not easy to handle. for example, A, B, and C are three queries. A must be performed first, and B can be performed only after filtering based on the results, there are sequential requirements and there is no way to get the query results at a time.

Second, it is not convenient to query the results of a row locally in some queries, unless the business logic is modified a lot.



In the afternoon, the two machines are put on the wired LAN for testing, which is greatly accelerated. in the case of wireless LAN, the ping value is about 20 ms, and in the case of wired networks, the ping value is less than 1 ms, therefore, more than 100 calls are only about 70 ms. in this case, the latency is not a problem.

In one app request, php and mysql have hundreds of interactions?
A single request has hundreds of interactions ?..

If the database is separated from php, there will be a certain amount of network latency.
Suggestion:
1. enable cache to reduce access to the database.
2. optimize the database structure and indexes.

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.