PHP set timeout for script with system call, set_time_limit not working

Posted by tehalive on Stack Overflow See other posts from Stack Overflow or by tehalive
Published on 2010-04-08T22:33:25Z Indexed on 2010/04/09 0:23 UTC
Read the original article Hit count: 439

Filed under:
|
|
|

I have a command-line PHP script that runs a wget request using each member of an array with foreach. This wget request can sometimes take a long time so I want to be able to set a timeout for killing the script if it goes past 15 seconds for example. I have PHP safemode disabled and tried set_time_limit(15) early in the script, however it continues indefinitely. Update: Thanks to Dor for pointing out this is because set_time_limit() does not respect system() calls.

So I was trying to find other ways to kill the script after 15 seconds of execution. However, I'm not sure if it's possible to check the time a script has been running while it's in the middle of a wget request at the same time (a do while loop did not work). Maybe fork a process with a timer and set it to kill the parent after a set amount of time?

Thanks for any tips!

Update: Below is my relevant code. $url is passed from the command-line and is an array of multiple URLs (sorry for not posting this initially):

foreach( $url as $key => $value){
    $wget = "wget -r -H -nd -l 999 $value";
    system($wget);
    }

© Stack Overflow or respective owner

Related posts about php

Related posts about linux