Windows Server 2008 R2 and 2012 the PHP connection to MySQL too slow solution _php tips

Source: Internet
Author: User
Tags install wordpress

Compare the speed of the following two scripts:

    • Windows 7 connects local MySQL with localhost, which can be slow.
    • Windows 7 connects local MySQL with 127.0.0.1, and the speed is normal.

My.ini is configured in the

bind-address=127.0.0.1

Connect local mysql with localhost: slow

<?php
$start = Microtime (true);
$mysqli = new Mysqli (' 127.0.0.1 ', ' root ', ', ', ' MySQL '); The connection takes only 0.0025 seconds.
$mysqli = new mysqli (' localhost ', ' root ', ', ', ' MySQL '); The connection takes more than 1 seconds and is 400 times times slower than normal.
Echo Microtime (True)-$start;

Analysis:
1.my.ini in the configuration

bind-address=127.0.0.1

, Win7 and its version of the system PHP with localhost to connect to MySQL time consuming more than 1 seconds, compared with the 127.0.0.1 connection is 400 times times slower.
2.my.ini in the configuration

Bind-address=::1

, Win7 and above version of the system PHP with localhost connection mysql speed is normal, but with the 127.0.0.1 connection is not normal.
3. Remove Bind-address configuration, then use localhost or 127.0.0.1 connection MySQL speed is normal.

So: In the configuration of the

 
 

, you should use 127.0.0.1 to connect to the local MySQL database.
Install WordPress, phpMyAdmin and other PHP programs when the default use localhost to connect to the local MySQL database, then note that the default localhost to 127.0.0.1.

In addition, Windows 2008 and 2012 have the same problem with Windows 7.

Related Article

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.