Hi Guys !
I need to execute some external unix commands from a PHP page .. and capture the output to a variable.
Furthermore, I want to display the command output "real-time" - so that my users can see what the command does.
I've come up with this function :
function RunCmd ($cmd="", $arg="") {
// Reset Result buffer
$res = "";
// Escape Shell stuff ..
$cmd = escapeShellCmd($cmd);
$arg = escapeShellCmd($arg);
// Do more sanity checks here .....
ob_implicit_flush(1);
echo '<pre>';
$fp = popen ( $cmd . " " . $arg . " 2>&1", "r");
while ($line = fgets ($fp, 4096) ) {
echo htmlentities($line);
$res .= $line;
}
pclose ($fp);
echo '</pre>';
ob_implicit_flush(0);
return ($res);
}
Works like expected, but when a user aborts the PHP script, the external command continues. The BIG problem is, that the user cannot access any pages on the web-server while the external command is still running. It kind of locks the session.
How can I avoid this ?
Thanks for your input...
/Tom