Forum Moderators: coopster

Message Too Old, No Replies

mysql connect and timeout

         

webstyler

2:19 pm on Nov 7, 2009 (gmt 0)

10+ Year Member



Hello

I have a connection to mysql as

$ndb = mysql_connect($host,$dbuser,$dbpass, TRUE) or die ("Database Connection Error<br>");

There are many php function tah can be take many time, so after this I check if connection is live with

if (!$ndb)
..
reconect code
..

Problem is that $ndb is always TRUE also when is timeout (by wait_timeout on my.cnf)

So, how check if connection is live and not timeout ?

Thanks

bkeep

9:12 pm on Nov 9, 2009 (gmt 0)

10+ Year Member



PHP itself has a script execution time. I am not 100% sure and someone else may want to step in but you should only need to connect to the database once per script execution for mysql. if you are having timeout issues with the script check your process and possibly post the exact error you relieve.

eelixduppy

10:00 pm on Nov 9, 2009 (gmt 0)



The problem here seems to be your mysql timeout. What is it set to? Why do you have it timeout?

PHPcoder

11:35 pm on Nov 9, 2009 (gmt 0)

10+ Year Member



i think in general most hosting provider set a timeout to prevent a query hanging indefinitly.

what if somebody was to run while loop but forget use a break out

webstyler

7:47 am on Nov 10, 2009 (gmt 0)

10+ Year Member



Hello

mysql_connect report TRUE also when connection is timeout

solved with mysql_ping that check if really live ;)

Thanks