By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,062 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,062 IT Pros & Developers. It's quick & easy.

set_time_limit(), using includes, & strange timeout behaviour

P: 93
I'm trying to investigate the way PHP behaves in relation to timeouts and included scripts. PHP seems to do very strange things when scripts that include other scripts timeout, or when the included scripts themselves timeout. Just wondering if anyone else has ever investigated this world of mystery, or if they would like to join me in my quest into the unknown!!....??

It appears that in some cases php will return a completely balnk page when a script times out (no "Fatal error...." message, despite 'display errors' being well and truly turned on). Or sometimes it will display the error message. I haven't quite figured out what it is that causes these different behaviors.

It would seem that if you do this:
include 'some_script.php';[/PHP]

For those of you without super-human, badly-coloured-code-reading abilities that's:
<?php set_time_limit(40);
include 'some_script.php'; ?>

Then 'some_script.php' is also given a maximum execution time of 40 seconds.

And this is the bit that's really strange...
If you have this:
include 'tedious_loop.php';
include 'tedious_loop.php';
include 'tedious_loop.php';
include 'tedious_loop.php';[/PHP]
(set_time_limit(20); include 'tedious_loop.php' 4 times)

And 'tedious_loop.php' takes 7 seconds to execute, e.g.:
//do nothing
(a loop that does nothing for 7 seconds)

Then your script will sometimes timeout, and sometimes wont (despite the fact that the whole thing will always take 28 seconds). The time that 'tedious_loop.php' takes to execute is not counted as part of the execution time of your main script. Well not entirely anyway. But like I said, sometimes it will cause your script to timeout and sometimes it wont. Can anyone else shed any light on this?
Jun 2 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.