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?
This is not possible because the underlying MySQL driver won't allow it:
Request #60716: Ability to set PDO connection timeout in milliseconds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With