php - How do I shorten the MySQL Connect Time Out - Failover Scenario -



php - How do I shorten the MySQL Connect Time Out - Failover Scenario -

i have fail-over scenario in wordpress plugin, php script on web server tries connect backup database if production 1 offline.

currently fallback seems take 60 seconds. php default? how set time out 10 seconds?

here relevant portion of script...

seek { $dbblue = new \pdo('mysql:host='.$samhost.';'.'dbname='.$dbblue, $samuser, $sampass); $dbgreen = new \pdo('mysql:host='.$samhost.';'.'dbname='.$dbgreen, $samuser, $sampass); } grab (\pdoexception $pde) { // fallback database connection $althost = get_option('fallback_host'); $altuser = get_option('fallback_user'); $altpass = get_option('fallback_password'); $dbblue = new \pdo('mysql:host='.$althost.';'.'dbname='.$dbblue, $altuser, $altpass); $dbgreen = new \pdo('mysql:host='.$althost.';'.'dbname='.$dbgreen, $altuser, $altpass); }

try this:

$dbblue = new \pdo('mysql:host='.$samhost.';'.'dbname='.$dbblue, $samuser, $sampass, array( pdo::attr_timeout => "10", pdo::attr_errmode => pdo::errmode_exception )); $dbgreen = new \pdo('mysql:host='.$samhost.';'.'dbname='.$dbgreen, $samuser, $sampass, array( pdo::attr_timeout => "10", pdo::attr_errmode => pdo::errmode_exception ));

pdo::attr_timeout => "10" ->>> set timeout 10 seconds.

pdo::attr_errmode => pdo::errmode_exception ->>> throw exception.

more info : http://php.net/manual/en/pdo.setattribute.php

php wordpress

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -