Executing and checking background shell process from PHP
23rd May 2007
Found a nicely illustrated method for running a background shell command from PHP and continuously checking if the process is still running.
Here's sample code without explanations:
PHP:
- function run_in_background($Command, $Priority = 0)
- {
- if($Priority)
- else
- return($PID);
- }
- function is_process_running($PID)
- {
- }
To run something like hmmsearch from the HMMER package, you’d do this:
PHP:
June 24th, 2009 at 9:55
function is_process_running($PID)
{
exec("ps $PID", $ProcessState);
return(count($ProcessState)>= 2);
}
IMO, it is more elegant to check for the exit code instead.
June 24th, 2009 at 10:23
Joe,
how would you do that, given the example application above? I see no way of getting exit status from a process which has finished.