php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45150 MySQL functions cannot be used with 5.3.x on Vista when using "localhost"
Submitted: 2008-06-02 16:46 UTC Modified: 2010-11-16 11:00 UTC
Votes:7
Avg. Score:5.0 ± 0.0
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:7 (100.0%)
From: conor dot kerr_php at dev dot ceon dot net Assigned:
Status: Not a bug Package: MySQL related
PHP Version: 5.3CVS-2008-07-23 (snap) OS: Windows Vista
Private report: No CVE-ID:
 [2008-06-02 16:46 UTC] conor dot kerr_php at dev dot ceon dot net
Description:
------------
I've been trying the PHP 5.3.x snapshots out for the past two weeks on three separate Vista systems and consistently got timeouts when a mysql_connect function was encountered.

Tried rebooting into Windoze XP on one of the systems and installing on it and everything worked perfectly straight away.

Tried everything I could on the Vista systems, removing all copies of libmysql.dll from the system, changing the PATH, removing the path, (restarting after all changes) but every time PHP the mysql_connect function times out.

Are the snapshots tested on XP only? I've spent almost a full working day over the past two weeks trying to get 5.3 running in my normal environment so that I could start using the namespace functionality. Sadly I now have no choice but to use XP anytime I need to run anything I write as 5.3 clearly isn't compatible with the combination of Vista and MySQL. :(

Any PHP script that doesn't use MySQL works fine on all three Vista systems.

Reproduce code:
---------------
<?php
print "connecting...";
mysqli_connect('localhost:3307', 'root', '');
?>

Expected result:
----------------
No errors. :)

Actual result:
--------------
Warning: mysql_connect() [function.mysql-connect]: [2002] A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3307) in C:\Program Files\Glossword-WAMP\htdocs\test8.php on line 3

Warning: mysql_connect() [function.mysql-connect]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\Program Files\Glossword-WAMP\htdocs\test8.php on line 3

Patches

Stupid (last revision 2011-09-29 05:33 UTC) by i at gmail dot com)
ii (last revision 2011-09-29 05:31 UTC) by sfvjf at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-13 14:09 UTC] conor dot kerr_php at dev dot ceon dot net
Hi,

Has anyone taken a look at this?

I've managed to get PHP5.3 working fine with MySQL on Mac OS X, Linux (RedHat 9 - old I know but anyway :) ) and Windoze XP but mysql_connect times out on any Windoze Vista system.

If anyone has got 5.3 working with MySQL on Vista could they please e-mail me to say so. If not, could this be looked at soon?

Thanks,

Conor
 [2008-07-13 15:05 UTC] jani@php.net
Are you sure it's not some "security" feature in Vista that is blocking the connections? I'd check firewall settings, etc.
 [2008-07-18 07:46 UTC] conor dot kerr_php at dev dot ceon dot net
Thanks for replying! I've disabled all the security checks as this is a development machine so that can't be it. :( 

I haven't come across a single person trying 5.3 (via Apache) and the new MySQL extension out on a Vista machine.. can anyone please confirm that they have it working?
 [2008-07-18 16:54 UTC] conor dot kerr_php at dev dot ceon dot net
Hi,

Finally got this sorted.

Took a more methodical debugging attitude to this and reduced the mysql.connect_timeout to 5 seconds.

Started to get error messages at last - so the mysql_connect function that wasn't failing altogether.

Quickly determined that on Vista SP1, PHP5.3 can't resolve "localhost" to "127.0.0.1" in the mysql_connect function.

Stopping Apache, pointing LoadModule php5_module ... and PHPIniDir ... back to 5.2.x then restarting Apache allows the mysql_connect function to work again (as expected).

This is using a stock hosts file on Windoze, which is correctly set up for localhost.

I'm not sure where the bug is but could it possibly be something to do with IPv6? Does PHP5.3's new mysqlnd default to using IPv6 first which then isn't resolving properly to 127.0.0.1? I only ask that as 5.2.6 works perfectly on the same machine(s) and the only difference I can see is the use of mysqlnd.

I could be barking up the wrong tree altogether though, but I can confirm that PHP5.3.x can't resolve localhost when connecting to MySQL on Vista whereas it can on XP and 5.2.6 never has any troubles on the same machines (without any reboots).

Also, FYI, hadn't tried this procedure before because command line commands to mysql work using "localhost" as well as "127.0.0.1" (as would be expected if Apache+PHP5.2.6 also worked) so it never occurred that there could be problem resolving localhost.

At least I've got a solution for anyone out there... replace "localhost" with "127.0.0.1" in your scripts... until anyone @php.net can help us out with a fix/answer of course!

Thanks again Jani for the post, it at least encouraged me to try and debug this more methodically and now I don't have to reboot into OSX or XP or upload scripts to a Linux server to out the new namespace functionality! :)

All the best..

Conor Kerr
http://ceon.net
 [2008-07-23 11:24 UTC] andrey@php.net
Hi,
mysqlnd uses the PHP streams, compared to libmysql, which does the network i/o itself. Thus, if mysqlnd can't resolve localhost to 127.0.0.1, then PHP should not be able too. Could you try to reproduce that. mysqlnd does nothing special, just uses IPv4 to open a TCP connection.
 [2008-07-23 13:03 UTC] conor dot kerr_php at dev dot ceon dot net
Hi Andrey,

Thanks for replying. You have found the problem!

Running the following test script:

<?php

$httpfile  = file_get_contents("http://127.0.0.1/foo.txt");

print "File contents read using 127.0.0.1: \n\n" . $httpfile . "\n\n";

$httpfile  = file_get_contents("http://localhost/foo.txt");

print "File contents read using localhost: \n\n" . $httpfile . "\n\n";

?>

Gives the following results:

---
File contents read using 127.0.0.1: This is the content of foo.


Warning: file_get_contents(http://localhost/foo.txt) [function.file-get-contents]: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in E:\_CEON\Web\test\php_streams.php on line 7

Fatal error: Maximum execution time of 60 seconds exceeded in E:\_CEON\Web\test\php_streams.php on line 7
---

So PHP 5.3 can't resolve localhost to 127.0.0.1 on Vista.

Should I update this bug to show that it is a streams problem?

Or close this bug and start a new one for Vista + Streams in 5.3?

Thanks again for the reply.

All the best...

Conor
 [2008-07-23 13:27 UTC] conor dot kerr_php at dev dot ceon dot net
Okay,

I've looked into this further and tested with PHP5.2.6 on the same setup and get the same problem.

I've seen a few bugs in the database which refer to this same localhost/127.0.0.1 issue.

I agree that it's not a PHP issue.

However, it will become a serious enough issue for people when they move to 5.3 from a previous version as many PHP-based open source software packages use "localhost" as their default database server host.

A lot of people will waste a lot of time unless it is made prevalent somewhere that:

"127.0.0.1" should be used instead of "localhost" on Vista

OR: 

the line "::1  localhost" should be commented out in the hosts file for Vista: "#::1  localhost"

Where is the best place to put this information? At the very least, it should be part of the upgrade notes for 5.3 as, I'm willing to bet, many PHP developers haven't previously used streams and this issue will not have affected them until they upgrade to 5.3, at which point MySQL will constantly time out on them because it does use streams and therefore is susceptible to this windoze bug.

Hopefully there are no "Badly configured OS is not a PHP bug -> Bogus"-type replies to this, that would not be helpful for the PHP community at large!

This information needs to be made prevalent somewhere regarding 5.3.

Thanks,

I hope I've been of help to some others!

All the best...

Conor
http://ceon.net
 [2010-03-05 20:46 UTC] changeorders at gmail dot com
Fresh install of PHP 5.3.x on Server 2008. Same problem. Had to comment out the IPv6 entry for localhost in the hosts file. This is still a bug.
 [2010-03-05 20:51 UTC] pajoye@php.net
-Status: Closed +Status: Bogus
 [2010-03-05 20:51 UTC] pajoye@php.net
That's not a bug, please refer to the dozen other reports about that.
 [2010-03-16 13:55 UTC] achurkin at gmail dot com
Same on Windows 7 Home Edition.
In PHP version 5.2.9 on same system everything works fine.
 [2010-04-05 07:52 UTC] telstra at dark-media dot net
Had the same problem on Windows Server 2008 R2 had to edit the hosts file and un comment out the 127.0.0.1 localhost

Was stumbled for a while after upgrading from 5.2 to 5.3, this might not be a bug with PHP but its something that is going to cause issues.
 [2010-04-10 03:58 UTC] buana95 at yahoo dot com
Same issue on Windows XP SP3 and PHP 5.3.1 with mysqlnd 5.0.5-dev - 081106 - $Revision: 289630 $. 

Work fine when using *libmysql.dll, but can not connect to database when using *mysqlnd.dll (tested on mysql, mysqli, and PDO extension).

***

From MySQL website: they have resolved the issue by looping to all available IP (IPv4 - IPv6) and return the first successful connection.

So, it's must be from PHP streams that fail to resolve IPv6.

Never test on newer PHP version. Sorry.
 [2010-04-19 04:13 UTC] sasavilic at gmail dot com
I have same issue. Using Windows 7, 64-bit, IIS

When I try to connect to mysql server on 127.0.0.1 everything works fine, but with localhost not.
 [2010-05-11 08:30 UTC] kiewic at gmail dot com
Same problem with Windows Vista Ultimate SP2. Why isn't this a bug?
 [2010-09-06 08:51 UTC] songchongzhan at gmail dot com
Did you disable networking on windows. I use MySQL Query Browser connect to MySQL, 
it has MySQL Error Number 2003. Use mysqli connect to MySQL, it return like what 
you post:[2002].....
And I use named pipe connect to MySQL by MySQL Query Browser, it is OK, by php 
5.3.x does not support it util now.
Try to open MySQL network connection.
 [2010-09-06 11:18 UTC] uw@php.net
Bogus AKA duplicate http://bugs.php.net/bug.php?id=48082
 [2010-09-11 16:32 UTC] zarlean at yahoo dot com
I got this to work in Windows 7 (Apache 2.2, PHP 5.3.3, MySQL 5.1.44) 
by adding the line

127.0.0.1 localhost

to the hosts file in C:/Windows/System32/drivers/etc/
 [2010-10-19 01:39 UTC] iswald at yahoo dot com
Same problem, 127.0.0.1 works, but localhost times out in MySQL, though not SQL Server. Went to add 

127.0.0.1 localhost

to the hosts file, however, it was already there. Not Fixed. Needs better documentation at least, even if it is a MS problem.

(PHP 5.3.3.0, MySQL 5.1.51, Windows Vista SP 2, no Apache)
 [2010-11-16 04:18 UTC] slava at shabrov dot com
Just upgraded PHP to v 5.3.3 and got this problem. This thread helped.
In addition to adding to the 'host' file
127.0.0.1       localhost 
you need to comment out 
#::1             localhost 

Fixed this issue to me. I would blame here MySQL not supporting IPv6.

Windows 7 x64; PHP 5.3.3 FastCGI; MySQL 5.1.38
 [2010-11-16 11:00 UTC] pajoye@php.net
-Block user comment: N +Block user comment: Y
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Thu May 25 16:01:43 2017 UTC