Forum Moderators: coopster

Message Too Old, No Replies

Set PHP's timeout for database only?

In the hypothetical situation where the database is down.

         

JAB Creations

6:09 am on Jun 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd like to reduce the timeout for waiting for a response from the database when the database is down. By default it looks like it's about a minute which means the browser will hang for a minute. I already have my work handle things correctly when the database is down, I just don't want to wait 60 seconds every time I reload the page while I test with the database intentionally disabled or for users to wait that long in a live environment especially since that will create unnecessary load and most users will leave if the page is going to hang for even half that length.

I have tried the following however it spawns an error whereas currently by default if the database is not available it just continues loading normally without errors...

set_time_limit(5);


Thoughts please?

- John

Anyango

8:49 am on Jun 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Maybe this is the last possible option you should try, because this will change things server wide but if no other solution, try changing this value in php.ini

mysql.connect_timeout

By default it will be set to 60 seconds if i am not wrong. maybe this value can be set via ini_set for your script, not sure and didnt try it.

Hmm, nah wait a second. it can be set via ini_set for your script alone so it wont effect server wide.

Reference

[php.net...]

coopster

10:31 am on Jun 26, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Correct, settings for the DB have to be done at the SQL server level either via the DB configuration or a per-event override like changing a setting in your script. Changing PHP time limits and execution directives have no impact on external processes. Details are in the notes on the set_time_limit [php.net] manual page.

Note: The set_time_limit() function and the configuration directive max_execution_time only affect the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), stream operations, database queries, etc. is not included when determining the maximum time that the script has been running. This is not true on Windows where the measured time is real.