Php has some experience in array comparison. [difficult]

Source: Internet
Author: User
Tags mysql functions
Php has more experience with arrays. come and see [troubleshooting] PHPcode $ arr = array (); $ query = $ db-& gt; query (& quot; SQL statement & quot ;); while ($ row = $ db-& gt; fetch_array ($ query) {$ arrtmp ['co php has more experience with arrays to see [difficult]
PHP code
  $ Arr = array (); $ query = $ db-> query ("SQL Statement"); while ($ row = $ db-> fetch_array ($ query )) {$ arrtmp ['content'] = $ row ['content];... $ Arr [] = $ arrtmp ;}


An array is used to store the queried data, including headers and summaries.

The problem is that the mysql database is connected to the local database and the test speed is very fast, but the remote connection to the mysql database is very slow. skip-name-resolve is useless and can be ruled out.
I have not solved this problem for a few days. I am very puzzled. ask Daxia!

------ Solution --------------------
The mysql database is connected to the local database, and the test speed is very fast, but the remote connection to the mysql database is very slow.

Solutions for large nodes RAD database

Other solutions
1. set the database to synchronize database data locally at regular intervals
2. cache data
3. host the local server to the same data center as the database
------ Solution --------------------
Discussion

Additionally, the remote connection speed from the mysql server to the server where the program is located is fast.

------ Solution --------------------
This is, of course, the host and database are not on the same server, it must be slower, and you can't see the above code. Unless you have other code.
------ Solution --------------------
That is, the data transmission speed is too high and slow. Consider the output of the compression results. However, I have not processed the compressed data, so check whether others have experience.

Discussion

The crux of the problem is to save $ arrtmp ['content'] = $ row ['content];
This problem occurs when I comment on some big data at a very fast speed, but this data is required.
I would like to ask what is the optimization for storing big data in arrays. why is mysql remote connection very slow, but local connection very fast?

------ Solution --------------------
The result set obtained by mysql_query is cached on the mysql side.
Mysql_fetch_array reads the record cached in mysql each time.

So every time you read a remote data transmission, it is naturally slow.

Mysqli has a function that can retrieve the query result set at one time and cache it locally.
However, the function name is hard to remember (because mysqli is not used). It was discussed here in the previous two months.

Pdo provides the fetchall method to convert a result set to an array at a time.
It seems that mysqli also provides

As long as your database class is not based on mysql functions, there is always a way to solve the problem of slow remote reading.

------ Solution --------------------
Now, do not use the original php mysql function.
Change to mysqli or pdo.
Particularly, pdo is easy to use.
------ Solution --------------------
Assume that the time for reading a record is 50 ms.
Then 50 records are 50*50 = 2500 MS = 2.5 s

The ping result is the average time consumed by a single side.
Communication is bilateral.

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.