Jump to content

Connection timeout due to sleep()


phixx

Recommended Posts

Hi,

 

I have a script that starts out with establishing a connection:

$dbConnection = mysql_connect(.., .., ..);

mysql_select_db(.., $dbConnection);

 

Problem is that my script calls some functions - and these functions call other functions - and one of the sub-sub-functions has a sleep() for 10-20 seconds.

 

The sleep() causes my mysql connection to timeout (error on mysql_query() is "MySQL server has gone away"). If I remove the sleep() I can run the script without any errors.

 

Unfortunately removing the sleep() in production isn't an option, so what can I do to avoid the timeouts?

 

Thanks a lot,

Phixx

Link to comment
https://forums.phpfreaks.com/topic/162532-connection-timeout-due-to-sleep/
Share on other sites

if I don't give them a short break once in a while

Ummm. Computers don't get tired. They can perform the same task indefinitely. As always, you need to find and fix the problem that lead you to believe you must insert the seep(). If you have a timing issue, you can probably solve that with some handshaking/conditional logic.

I got an idea:

 

Make a global variable, $dbConnection

 

Wrap sleep in disconnect/connect, like this:

mysql_close($dbConnection);

 

sleep(20);

 

$dbConnection = mysql_connect(...);

mysql_select_db(..., $dbConnection);

 

Problem is that mysql_error still returns "MySQL server has gone away" :(

 

Why is that?

 

Thanks,

phixx

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.