php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #60716 Ability to set PDO connection timeout in milliseconds
Submitted: 2012-01-11 17:20 UTC Modified: 2016-10-10 22:37 UTC
Votes:10
Avg. Score:4.6 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:4 (50.0%)
Same OS:5 (62.5%)
From: markrose at markrose dot ca Assigned:
Status: Open Package: PDO MySQL
PHP Version: 5.4.0RC5 OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-01-11 17:20 UTC] markrose at markrose dot ca
Description:
------------
I'd like the ability to set PDO's connection timeout (to MySQL specifically) in 
milliseconds. The lowest the timeout can current be set to is 1 second, which is 
an extremely long time to wait for a database machine to reply.

I run a synchronously replicated MySQL environment (Galera), and I'd like to be 
able to move on to the next machine if the database doesn't respond in say, 10 
ms. Instead, PHP waits one second. This reduces the throughput of my PHP scripts 
from several hundred per second to only a handful per second, severely impacting 
performance and quickly exhausting the PHP thread pool, leading to timeouts.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-02 07:32 UTC] uw@php.net
For the MySQL part this can be considered Bogus/Not a bug because PHP is the wrong place to ask for it. Please, file a bug at MySQL.

The underlying MySQL C API does not offer sub second granularity for setting the connect timeout. If it was to be fixed, it should be done at the lowest level which is the MySQL C API. No matter whether we are talking mysqlnd or MySQL Client Library (libmysql). See also http://dev.mysql.com/doc/refman/5.6/en/mysql-options.html and http://blog.ulf-wendel.de/?p=273

For the PDO part, I am not too keen of driver specific settings. What's the purpose of PDO if not providing an abstraction for it... However, for years now PDO seems kind of neglected, nobody feeling too much responsible for it.
 [2012-08-08 15:56 UTC] marc-bennewitz at arcor dot de
I would like it because 1second can be a long time if you would like to connect to a failover server you have minimum of 2x1 seconds.

Sure if it's not possible with libmysql it's a MySQL-BUG only but for mysqlnd (and other db driver) it could be done.

The simplest way would be to allow a float value as timeout and if the driver supports it use it else round it up to the next second.
 [2013-06-12 03:44 UTC] ssufficool@php.net
-Summary: Ability to set PDO connection timeout in milliseconds +Summary: PDO_MySQL: Ability to set PDO connection timeout in milliseconds
 [2016-10-10 22:37 UTC] adambaratz@php.net
-Summary: PDO_MySQL: Ability to set PDO connection timeout in milliseconds +Summary: Ability to set PDO connection timeout in milliseconds -Package: PDO related +Package: PDO MySQL
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC