Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.