I just upgraded to PHP 5.3 on my Windows development box, and ran into an issue making any database connection with the MySQL and MySQLi drivers. Pages not making any database connections worked fine, but any page with a database connection would sit and hang for about a minute, and then throw an error.
PHP Warning: mysqli::mysqli():  A connection attempt failed because the connected party did not (trying to connect via tcp://localhost:3306) in xxx.php on line 2
PHP Warning: mysqli::mysqli(): (HY000/2002): 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 xxx.php on line 2
PHP bug #45150 suggests that this is due to issues resolving localhost on Windows. This is partially correct, more specifically it's an issue with localhost resolving to ::1 when IPv6 is enabled.
While it feels like Windows has shoehorned in IPv6 support, the blame seems to lie with MySQL, which won't support IPv6 until version 6.0.
I'm not sure why the timeout isn't instant, the port is closed, so it could be partially a problem with PHP or Windows.
> nmap -sT -p 80,3306,3389 -6 ::1 Starting Nmap 5.00 ( http://nmap.org ) at 2009-11-20 15:48 Mountain Standard Time Interesting ports on cfg64 (::1): PORT STATE SERVICE 80/tcp closed http 3306/tcp closed mysql 3389/tcp open ms-term-serv Nmap done: 1 IP address (1 host up) scanned in 3.14 seconds
%windir%\system32\drivers\etc\hosts with a text editor and comment out the line that looks like:
Prefix it with a #, like so:
Save it and your PHP/MySQL connections will immediately begin working. You could also use 127.0.0.1 in your connection string instead of localhost, but I didn't want to change code in innumerable files.