php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51085 Mysql Connect takews too long
Submitted: 2010-02-18 16:45 UTC Modified: 2010-02-18 23:59 UTC
From: djokodonev at gmail dot com Assigned:
Status: Not a bug Package: Performance problem
PHP Version: 5.3.1 OS: windows 7
Private report: No CVE-ID: None
 [2010-02-18 16:45 UTC] djokodonev at gmail dot com
Description:
------------
The mysql_connect function takes too long to connect to the host.

As shown below, the example code I've written, makes a connection to the local database(mysql) running on port 3306.

It worked just fine before i upgraded to windows 7.. It is quite possible that this is OS related than php related but still.

I would surely appreciate any feedback.

Regards

Reproduce code:
---------------
---
From manual page: http://www.php.net/function.mysql-connect#Parameters
---

// Test Code
$start = microtime(true);

$conect = mysql_connect("127.0.0.1:3306", "root", "myPassword");
$end = microtime(true);

echo $end - $start;//  0.500825881958 sec.

// results is -> 0.500825881958 sec...??? it is taking too long to connect for some reason??? Is it PHP related or?


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-18 16:52 UTC] djokodonev at gmail dot com
-Bug Type: Documentation problem
+Bug Type: Performance problem

It's a Performance problem...
 [2010-02-18 17:42 UTC] aharvey@php.net
-Status: Open
+Status: Bogus

This looks broadly similar (albeit on a different OS) to bug #48051, which wasn't a PHP issue as such either. Try disabling any firewalls you have enabled, check that MySQL isn't under undue load, see if connections from other applications (such as the MySQL command line client) also have a similar delay, et cetera.

At any rate, your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions.

Thank you for your interest in PHP.
 [2010-02-18 23:59 UTC] djokodonev at gmail dot com
Yes,

Well there isn't any load on the Machine, neither queries slow or any.

Already tried disabling the Firewall it gave no result. 

Tried entering "localhost", 127.0.0.1, "localhost:3306", etc. They all gave the same result. So it is not a DNS issue? as far as i can tell. 

But just in case i have the localhost added in the win/system32/drivers/etc/hosts file mapping to 127.0.0.1


I've tried opening MYSQL from the command line(cmd) and it seems instantaneous  connection compared to the 0.5 sec that takes php (mysql_connect) to connect.

NOTE that the Delay is always 0.5 sec. (+- 0.02) sec.

I simple doesn't makes sense but a lot of things don't i guess =).

And the configuration I am running is exactly thee same one as before. I triple or checked at least 10 times. I've been playing with this for at least 4 days now. 

Now I don't think that i can find a book or go to seminar or anything that i offered on the php support page. 

Anyways it is not bogus... Maybe it is MYSQL related not php related but you'll be getting such requests a lot in the coming months with people going over to WIN 7.

I've tried all the Google Related pages to look up a solution to this problem and tried installing a few versions of php and mysql to test out whether there is any difference if one would work compared to other WITHOUT ANY RESULTS. 

And it would have been great if I could actually see where the delay is.. If it in the computer or something needs to be tweaked.. et. but i have no idea on how to do that.
 [2012-08-21 05:16 UTC] m dot mihailko at gmail dot com
I have the similar problem. Do you find a solution?
 [2012-10-29 00:23 UTC] mikegrey28 at hotmail dot com
I had WinXP 32 bits running EasyPHP.
My script connected to MySql in milliseconds.

Now I migrated to Win 7 64bit and the some code is now taking 1 second to connect 
to mySQL (with firewall ON or OFF, it's the same).

Maybe I should get an EasyPHP build for 64bit but I can't find it :S

Cheers.
 [2012-10-29 00:30 UTC] mikegrey28 at hotmail dot com
Solution in Win7 maybe the next one:

On Windows 7 localhost resolves to ::1, and MySQL doesn't support IPv6 as far as 
I know.

Connecting directly to 127.0.0.1 resolves this problem; but you can edit the 
hosts file to resolve localhost to 127.0.0.1, then localhost will work too:

Open C:\Windows\System32\drivers\etc\hosts
Remove the following line, if present: ::1 localhost
Add the following line, if not present: 127.0.0.1 localhost

--------
This solved my issue, now my connection takes 0.01 seconds instead of the 1 sec.

Cheers.
 [2013-03-16 00:07 UTC] info at daverandom dot com
For a full and detailed explanation of this problem and the solution see 
http://stackoverflow.com/a/15436435/889949.

Long story short: this is a Windows problem and not a PHP bug, and this bug report 
should be closed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 10:01:26 2024 UTC