Jump to content

setting a timeout on db connection


thom2002

Recommended Posts

Hi All,

 

 

First posting here and I come with a question  8)

 

 

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  :D

 

 

best wishes

 

Thom

 

Link to comment
https://forums.phpfreaks.com/topic/199587-setting-a-timeout-on-db-connection/
Share on other sites

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

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.