Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting PDO connection timeout time less than 1 second

Tags:

php

mysql

pdo

I'm using PHP and a PDO object to connect to mysql. I have 3 DB servers that my php code can connect to. If I try to connect to DB server #1 and the connection fails I would like to immediately try to connect to DB server #2. The lowest I can set the connection timeout time is 1 second with the code below.

$DBH = new PDO("mysql:host=$host;dbname=$dbname", $username, $password,array(PDO::ATTR_TIMEOUT => "1",PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

Ideally I'd like to set the timeout time to <50 milliseconds. Or 0ms if possible. Is there any way to do this?

like image 585
Francis Snipe Avatar asked Aug 29 '26 09:08

Francis Snipe


1 Answers

This is not possible because the underlying MySQL driver won't allow it:

Request #60716: Ability to set PDO connection timeout in milliseconds

like image 132
silkfire Avatar answered Sep 01 '26 00:09

silkfire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!