thom2002 Posted April 24, 2010 Share Posted April 24, 2010 Hi All, First posting here and I come with a question I have a script with database (script A) running on one server (Server A). I have a plugin script (script B) installed into script A. Script B connects to a database on another server (server B) Everything works perfectly - except... If server B goes down then script B times out and stops execution of script A. What I need to happen is... IF server B is unavailable, then script A ignores script B and continues execution of script A. And it needs to happen within 2 seconds. Is there any way to add code to script B to accomplish this? I am open to suggestions best wishes Thom Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/ Share on other sites More sharing options...
mrMarcus Posted April 24, 2010 Share Posted April 24, 2010 well, how are you connecting to this database? let's see some code. or are you just looking for theory? Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/#findComment-1047643 Share on other sites More sharing options...
thom2002 Posted April 24, 2010 Author Share Posted April 24, 2010 Thanks for taking a look $dbHost="000.000.000.000"; // ip address of server $dbUser="username"; $dbPass="password"; $dbDB="dbname"; $dbh=mysql_connect ("$dbHost", "$dbUser", "$dbPass"); mysql_select_db ("$dbDB"); Script B does an insert to db on server B. Then does a select from server B Then does an update to db on server A As you can see, straight forward connection to server B. Except no exit or die as I want script A to continue no matter what happens with the plugin script B. On one occasion server B went down and the script B timeout caused script A to also timeout. That is what I must avoid happening. best wishes Thom Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/#findComment-1047653 Share on other sites More sharing options...
mrMarcus Posted April 24, 2010 Share Posted April 24, 2010 why not just a simple: <?php if ($dbh = mysql_connect($dbHost, $dbUser, $dbPass)) { mysql_select_db($dbDB); //continue with script B on server server B; } else { //continue with script A; } ?> something like that. of course it all has to do with how your code/script is setup to in order to properly execute the conditions. Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/#findComment-1047657 Share on other sites More sharing options...
thom2002 Posted April 24, 2010 Author Share Posted April 24, 2010 Yep it really could be that simple It is amazing how a problem can be made more complicated than it is... when a potential disaster is thrown at you. Thank you best wishes Thom Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/#findComment-1047659 Share on other sites More sharing options...
mrMarcus Posted April 24, 2010 Share Posted April 24, 2010 no worries. just a second set of eyes was needed. Link to comment https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/#findComment-1047662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.