php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73757 Slow connection when using localhost as DSN
Submitted: 2016-12-16 07:59 UTC Modified: 2017-01-18 18:45 UTC
From: binarskugga at gmail dot com Assigned:
Status: Not a bug Package: PDO MySQL
PHP Version: 7.1.0 OS: Windows
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: binarskugga at gmail dot com
New email:
PHP Version: OS:

 

 [2016-12-16 07:59 UTC] binarskugga at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/pdo.construct
---

When connecting to PDO using the DSN, it is painfully slow on local if you're using "localhost". This can be fixed by using 127.0.0.1 at the moment.

Test script:
---------------
<?php

try {
    $pdo = new PDO(mysql:dbname=foo;host=localhost;port=3306", $config["SQL"]["USER"], $config["SQL"]["PASSWORD"]);
} catch(PDOException $exception) {
    die("Couldn't access SQL engine. (" . $exception->getMessage() . ")");
}

?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-16 08:00 UTC] binarskugga at gmail dot com
Tested with MySQL.
 [2016-12-20 19:39 UTC] danack@php.net
-Status: Open +Status: Feedback
 [2016-12-20 19:39 UTC] danack@php.net
The slowness is very likely to be how networks work on Windows:

http://stackoverflow.com/questions/11663860/mysql-connect-localhost-127-0-0-1-slow-on-windows-platform/11667268#11667268


If that issue is affecting you then, either changing MySQL to listen to IPv6 loopback address of ::1 would fix this, as would changing your network to only use an IPv4 address.

I pretty strongly recommend just using the actual IP address though, and just avoiding the magic localhost name.
 [2016-12-20 20:09 UTC] binarskugga at gmail dot com
-Status: Feedback +Status: Open
 [2016-12-20 20:09 UTC] binarskugga at gmail dot com
Thanks for the answer ! Indeed works with regular IPv4 address. Also didn't know it was trying to solve it into an IPv6 first.
 [2017-01-18 18:45 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2017-01-18 18:45 UTC] krakjoe@php.net
As mentioned, this is not a php bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC