mysql - PHP Check slave status without mysql_connect timeout issues -


I have a web app that has Master Microscope DB and four Sky DBS. I am all slaves (or almost all) only I want to handle SELECT questions. Our load-balancer automatically sends a sled machine to the user, because they are running Apache / PHP and serving webpages. I am using an included file to set up the connection in the database, such as:

// for master server (i.e. - update / write / delete statement) $ host = "10.0 .0 .x "; $ User = "xx"; $ Password = "xx"; $ Link = mysql_connect ($ host, $ user, $ password); If (! $ Link) (die ("The master database is currently unavailable, please try again later.") // this connection to local host $ Host_Local = "localhost" READ-ONLY (ie - SELECT Statement; $ User_Local = "xx"; $ password_value = "xx"; $ link_local = mysql_connect ($ Host_Local, $ User_Local, $ Password_Local); // If slave DB is down then return to master Fails (! $ Link_Local)) {$ Link_Local = mysql_connect ($ host, $ user, $ password); }

I then use the $ link for all the updated queries and use $ Link_Local as the connection to the SELECT statement until the slave server gets down from the database Everything works fine if the local DB is down, then $ link_local = mysql_connect () takes at least 30 seconds before attempting to connect the call to the local host and returns to the script, causing a large page Backlog job The literacy is and basically shut down the system (due to extremely slow response time).

Does anyone know better way to handle connections with slave servers through PHP? Or, is there a type of timeout function that can be used to prevent mysql_connect calls after 2-3 seconds?

Thanks for the help. I've discovered other mysql_connect threads, but have not seen any of the issues addressing this issue.

[MySQL] section of your php.ini, set this value:

 ; Maximum Time for Connect Timeout (in seconds) -1 means no limit mysql.connect_timeout = 1  

If you have 4 dB slaves, then you have a very good network Trust your server build that should respond to the DB request under 1 second.

Then go down your slaves! This is a problem!

Finally, every page request will not require a link from Master DB. You should try to keep a connection manager class in a location that will be determined by the type of query that is used by the database To do. This will reduce the number of connections with your Master DB.


Comments