nicktherockstar Posted November 24, 2008 Share Posted November 24, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/ Share on other sites More sharing options...
JonnoTheDev Posted November 24, 2008 Share Posted November 24, 2008 Place this at the top of the script. set_time_limit(5); The script will run for 5 seconds and then terminate with your defined error. Quote Link to comment https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/#findComment-697839 Share on other sites More sharing options...
nicktherockstar Posted November 24, 2008 Author Share Posted November 24, 2008 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 ??? Quote Link to comment https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/#findComment-698030 Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/#findComment-698032 Share on other sites More sharing options...
cooldude832 Posted November 24, 2008 Share Posted November 24, 2008 I agree logically you make no sense 1) You should know the DB you are looking for 2) You can not tell how long something will take till it happens 3) You can abrupt the connecting process that easily. Quote Link to comment https://forums.phpfreaks.com/topic/134006-allowing-x-time-to-connect-to-db-help/#findComment-698051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.