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.