Re: How to interrupt function execution after X seconds?
| From: | Stuart Dallas | Date: | Wed, 10 Jun 2015 10:03:20 +0000 |
| Subject: | Re: How to interrupt function execution after X seconds? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-324947@lists.php.net to get a copy of this message | ||
On Tue, 9 Jun 2015 at 22:00 helices <mike@mdsresource.net> wrote:
> I execute a system call via proc_open() that usually completes in less than
> one minute
>
> Sometimes, it hangs for many hours
>
> I want to exit this parent script after thirty (30) minutes with the error
> description on STDERR and I also want that system call process killed at
> this point
>
> Although, a test script using ticks and pcntl_alarm(1800) works using a
> while() loop, this does NOT work with my production system call
>
> What am I missing?
>
> Please, advise. Thank you
>
If it's a CLI script, and it sounds like it is, I would fork before calling
proc_open in the child, and have the parent watch the PID. It can then
terminate the child. I'm not certain that will kill the process that was
opened by proc_open, but that would be where I'd start.
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/