你可以試試這個,它已經發布的用戶巴赫裏在巴赫裏點信息爲exec
<?php
function PsExecute($command, $timeout = 60, $sleep = 2) {
// First, execute the process, get the process ID
$pid = PsExec($command);
if($pid === false)
return false;
$cur = 0;
// Second, loop for $timeout seconds checking if process is running
while($cur < $timeout) {
sleep($sleep);
$cur += $sleep;
// If process is no longer running, return true;
echo "\n ---- $cur ------ \n";
if(!PsExists($pid))
return true; // Process must have exited, success!
}
// If process is still running after timeout, kill the process and return false
PsKill($pid);
return false;
}
function PsExec($commandJob) {
$command = $commandJob.' > /dev/null 2>&1 & echo $!';
exec($command ,$op);
$pid = (int)$op[0];
if($pid!="") return $pid;
return false;
}
function PsExists($pid) {
exec("ps ax | grep $pid 2>&1", $output);
while(list(,$row) = each($output)) {
$row_array = explode(" ", $row);
$check_pid = $row_array[0];
if($pid == $check_pid) {
return true;
}
}
return false;
}
function PsKill($pid) {
exec("kill -9 $pid", $output);
}
?>
注意:似乎在運行shell變體之後,無論我做什麼,我都會發生超時:|所以......任何一個也可以添加一個筆記我如何修復我的PHP解析器? (如果不是我只是重新安裝apache) – zozo 2011-03-29 08:58:10