How to improve the efficiency of php and mysql cross-server

Source: Internet
Author: User
How does php and mysql increase efficiency across servers? At the end of this post, I edited an APP developed by littlebugu from 2014-03-2009:53:07. 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, how can we improve the efficiency of php and mysql cross-server?

This post was last edited by littlebugu at 09:53:07

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!
------ 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)
------ Solution --------------------
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.