Function Timeout
Posted: Wed Jan 24, 2007 2:47 am
Is there a way to timeout a function in PHP if it doesn't return a value in x seconds/microseconds?
For instance, if our primary MySQL database server is down, scripts will wait for 20 seconds while trying to connect. The scripts stack up on our web servers and cause a cascading failure. I need a way for mysql_connect to just return false or stop after one second and then I can write backup logic to display error messages to clients. Any suggestions? I'm aware of the set_time_limit function, but that will terminate the whole script. I need something to just terminate a function call.
TIA!
For instance, if our primary MySQL database server is down, scripts will wait for 20 seconds while trying to connect. The scripts stack up on our web servers and cause a cascading failure. I need a way for mysql_connect to just return false or stop after one second and then I can write backup logic to display error messages to clients. Any suggestions? I'm aware of the set_time_limit function, but that will terminate the whole script. I need something to just terminate a function call.
TIA!