Jump to content

Where do I call set_time_limit()?


jayarsee

Recommended Posts

Hi,

 

I was asking for help with this elsewhere, but after a week no one was able to answer my question so I thought someone here might be able to shed some light on it. My original question was:

 

"I have an action that instantiates an object, and that object instantiates a bunch of child objects, and so on. My question is, do I only have to set set_time_limit() once in the action, in order to have that rule propagate to the execution of all of its child objects, or do I also have to set this in each of the class files that it calls? I similarly need to set ignore_user_abort() which I haven't used before, and I have the same question for that."

 

To clear up confusion about what I was asking, I clarified this way:

 

"That the limit applies to the "script" is the ambiguity I'm confused about. Technically, the original file is one script, so you set the timeout for that. But when it instantiates and object whose class code is coming from another file, that's a different "script", so presumably it could have its own timeout. And that's what my question is. Does the time out value you set automatically propagate to every other file that file calls on, or is it isolated to that file?

 

If you set a time limit of 100 seconds, but instantiated an object from class code in a different file and called a long running method in it, and that file had a different time out, say of 30 seconds, the execution time of the original file would be limited to 30 seconds and not 100."

 

In sum, do functions like ignore_user_abort() and set_time_limit() automatically apply to all code in the files a particular "script" require_once()'s? Or would it have to be set in those files as well?

 

I would just test myself to find out, but the method I would use to do that would be sleep() and that time isn't counted toward set_time_limit() so it won't work.

 

Thanks very much for any clarification someone might be able to give.

Link to comment
Share on other sites

It applies to the beginning of code execution of a script until the end.  So if you start scripta.php and it includes scriptb.php and instantiates an object or does whatever, then it applies to the entire sequence of events until the script ends.  So putting it in the original scripts applies to the entire execution, so long as there is not another set_time_limit() in one of the other files.

Link to comment
Share on other sites

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.