Jump to content

allowing x time to connect to db help


nicktherockstar

Recommended Posts

Morning all,

 

I have another issue for you....

 

I have a php function that is called several times which connects up to different MSSQL DB's. This works great when they are there, but if we have a comms fail, the script trys for far too long to connect and normally fails to finish executing (60 seconds)

 

code...

 

 

//connection to the database

if(!$dbhandle = mssql_connect($myServer, $myUser, $myPass)){

echo "DOH! - COULD NOT CONNECT PART 1";

}

 

//select a database to work with

if(!$selected = mssql_select_db($myDB, $dbhandle)){

echo "DOH! - COULD NOT CONNECT PART 2";

}

 

 

What I would really like to do is only allow the script say 5 seconds to connect. Any ideas very much welcome!!!

 

Cheers guys ;D

Link to comment
https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/
Share on other sites

Thanks for this.

 

However it doesnt quite fit my needs... sorry I should explain

 

The issue is that the page connects out to a number of networked databases and checks a table on each to make sure everything is in working order.

 

now if there is a comms link down on one of the middle databases this would cause the script to stop.

 

what it needs to do is, attempt to connect for x seconds, then echo out if it does not connect. As in this case we are interested if the db cannot be connected to because its an internal tool and not a user application.

 

I guess it makes more sense if I point out the point of the script is to display the status of our systems. should one fail... thats ok but i need to show that and then go on to test the rest ???

Why?  Put some logic in so if it can't make a connection, it records that and moves on.  You don't need to allow any time for that, it will know soon as it tries to connect if it can or not.

 

 

now if there is a comms link down on one of the middle databases this would cause the script to stop.

 

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.