|  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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: binarskugga at gmail dot com
New email:
PHP Version: OS:


 [2016-12-16 07:59 UTC] binarskugga at gmail dot com
From manual page:

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

Test script:

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() . ")");



Add a Patch

Pull Requests

Add a Pull Request


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

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]
-Status: Open +Status: Not a bug
 [2017-01-18 18:45 UTC]
As mentioned, this is not a php bug.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 08:01:30 2024 UTC