Jump to content

using set_time_limit()


Go to solution Solved by requinix,

Recommended Posts

Why doesn't the following script timeout and return a fatal error after 2 seconds?  Thread Safety is disabled in PHP (is this what http://php.net/manual/en/ini.sect.safe-mode.php#ini.safe-mode is?)

 

Also, instead of returning a fatal error, how can I do something else such as just die?  I suppose I could use an error handler to do so, but expect there is a cleaner way.

<?php
echo("1\n");
set_time_limit(2);
echo("2\n");
sleep(4);
echo("3\n");
Link to comment
https://forums.phpfreaks.com/topic/302427-using-set_time_limit/
Share on other sites

I guess you need to give it over 2 seconds of actual work to do

 

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.

  • Solution

Originally, I was planning on making the blocking function indefinite, and just timeout the script

Anecdotally and without any sort of source to back me up, you shouldn't do an indefinite timeout on a blocking function. I think that's from personal experience. Do a "long" timeout of less than a minute, then worst case your loop just jumps back to the start and it starts blocking again immediately.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.