Web Hosting Talk







View Full Version : how to evalue that a program is still running with php script ?


jjk2
05-15-2009, 09:05 PM
okay so i thoguth about using shell_exec($cmd), however it only returns when it finishes.

i need to monitor that a program or job is running ie. exec("wget -r some.com")
and check every 25 seconds that the output doesn't have "Finished"

is this possible to do this in php with a while loop ?

WO-Jacob
05-16-2009, 12:59 PM
okay so i thoguth about using shell_exec($cmd), however it only returns when it finishes.

i need to monitor that a program or job is running ie. exec("wget -r some.com")
and check every 25 seconds that the output doesn't have "Finished"

is this possible to do this in php with a while loop ?

Yes, the exec tools are what you're looking for...

If go to: http://us3.php.net/manual/en/ref.exec.php

proc_open to get a handler, then proc_get_status periodically. :)

You may also need to check sooner than 25 seconds as I seem to recall it's easy to miss status changes...

alfyles
05-30-2009, 04:26 PM
Use nohup and run wget in the background so you won't have to wait until script is finished. Do loop check if process is running. Here is the sample code:


$PID = shell_exec("nohup wget -r some.com > /dev/null & echo $!");

function is_process_running($PID){
exec("ps $PID", $ProcessState);
return(count($ProcessState) >= 2);
}

while(is_process_running($TaskPID))
{
echo ".";
ob_flush(); flush();
sleep(2);
}