homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

How to mysql connect() to a different server if the other is overloade

5+ Year Member

Msg#: 3778049 posted 6:13 am on Nov 1, 2008 (gmt 0)

Ok, I know you can simply write a script that detect if a database is up or not, and then reconnect to another like so:

$con = mysql_connect($host, $user, $pass);
if (!$con) //try to connect to another database now


My question is, sometimes one of our databases is overloaded, it is still responsive but simply waits to connect because the load is to high. So the connect script just keeps loading, because the database is there. It just will never stop loading the php script because the database is alive, but is to overloaded to connect fast, so it just waits untill the load passes and then connects after its done.

Is there any way to modify it, where it'd say, if it can not connect within 5 seconds, for instance (because its overloaded) then try connecting to a different one.

if ( can't connect within 5 seconds to this database ) do something else?



WebmasterWorld Senior Member 10+ Year Member

Msg#: 3778049 posted 12:29 am on Nov 2, 2008 (gmt 0)

You should be able to accomplish what you need with the mysql.connect_timeout ini setting.

Another option would be to check the load on the database server (using a shell command) and use a second server if it's over (for example) 5.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved