我有两个带超时参数的exec()函数。 例如:
<?php
exec("timeout 5 /usr/local/bin/trun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$t_uptime);
exec("timeout 5 /usr/local/bin/wrun 'uptime;ps -elf|grep httpd|wc -l;free -m;mpstat'",$t_uptime);
?>
不工作。我想exec()
在5秒后停止,下一个exec()
函数开始执行。
请更正此问题或提供一些替代方法来停止exec()
功能
答案 0 :(得分:0)
exec - 执行外部程序
string exec ( string $command [, array &$output [, int &$return_var ]] )
exec() executes the given command.
答案 1 :(得分:0)
使用此功能 - 有关详细信息,请阅读http://in2.php.net/function.exec
function PsExecute($command, $timeout = 5, $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;
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;
}