Php5.4.8 connecting to mysql is slower than php5.2.6

Source: Internet
Author: User

I use the same script to test two versions of php. The notes are in Windows 7.

<? Php
$ A = microtime (true );
$ Conn = mysql_connect ("localhost", "root", "123456 ");
Mysql_select_db ("yqr ");
$ Q = mysql_query ("show tables ");
While ($ r = mysql_fetch_assoc ($ q ))
{
// Print_r ($ r );
}
Echo microtime (true)-$ a; echo "seconds"; exit ();
?>

The output result of php5.4.8 is:

 

1.0138568878174 seconds

Php 5.2.6 outputs the following results:
 

0.00234985351562 seconds

It can be seen that php5.4.8 is much slower to access mysql than php5.2.6. When I started using php5.4.8, I thought it was mysql that slowed down, deleted logs, and improved mysql performance. It was still not necessarily faster, and the speed was more than 1 second. Later, after I switched to php5.2.6, the access speed suddenly dropped to about 0.002 seconds. It does not seem like a problem with mysql, but with mysql extension in php. If you upgrade php5.4.8 to php5.4.8, pay attention to it.

Husband to php.net asked the master, the URL is: https://bugs.php.net/bug.php? Id = 63525 & thanks = 2. The expert's answer is: the simple solution is to replace localhost with 127.0.0.1. I did it, and the speed was faster. He said that because Windows 7 uses localhost as ipv6 for parsing, and mysql does not listen at: 127.

Connect to mysql take 0.0034029483795166 seconds

$ Conn =Mysql_connect ("127.0.0.1", "root", "123456"); // note that 127.0.0.1 should not be written as localhost.
 

Address: http://wudimei.com/yangqingrong/blog/show/133

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.