The recent local debugging site when individual programs such as PHPCMS has been this problem, the speed is unusually slow, and occasionally found the following article, just reminded me, the original question like this ...
When I recently developed my application on Windows, I found an interesting problem: my local program connects to the local MySQL library with a delay of about 1 seconds to open.
Problem analysis
Considering that it might be a program performance issue, I used the Xdebug performance Log function output program to run the log and found that the connection to MySQL function time actually used nearly 95% of the execution time.
The confirmation is MySQL performance problem, consider is the MySQL domain name back check function influence speed, let me disappointed is, in My.ini inside the closed domain name back check after the problem still exists.
Baffled when I had the whim to change the address of the server in the code from localhost to 127.0.0.1, the magical 1-second delay actually disappeared.
Switch to IP after incredibly good, is localhost exist what strange? Open cmd, enter ping localhost,ping output results I am very surprised:
Yes, localhost came out of the IPv6 address:: 1, then the reason for the second delay is also very easy to understand, using the localhost connection, the program resolved the address is IPv6 address:: 1, and then to try to connect to monitor this address of MySQL, And it is obvious that MySQL is listening to the IPv4 address 127.0.0.1, IPv6 does not even timeout will then go to connect IPv4 address 127.0.0.1, which is the reason for this 1-second delay.
Open the Hosts file for Windows and you will see the following comments
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
#:: 1 localhost
Solving method
Programme 1. Use 127.0.0.1 instead of localhost to connect to MySQL.
Programme 2. The edit Hosts file forces 127.0.0.1 to bind to localhost.