proc_open, proc_get_status 및 proc_terminate을 사용하여 SyncTable 작업을 프로세스로 시작하고 모니터링하고 필요한 경우 종료 할 수 있습니다. 주 : SyncTable 기능을 독립형 프로세스로 시작할 수 있도록 간단한 랩퍼 스크립트를 작성해야 할 수도 있습니다. 같은 Googlable, [수면] (
/// Executes a command and returns the output
/// If the timeout value (in seconds) is reached, it terminates the process
/// and returns FALSE
function exec_timeout($cmd, $timeout=30)
{
$descriptors = array(
0 => array('pipe', 'r'), // stdin
1 => array('pipe', 'w'), // stdout
2 => array('pipe', 'w') // stderr
);
$pipes = Array();
$process = proc_open($cmd, $descriptors, $pipes);
$result = '';
$end_time = time() + $timeout;
if (is_resource($process))
{
// set the streams to non-blocking
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
$timeleft = $end_time - time();
while ($timeleft > 0)
{
$status = proc_get_status($process);
$result .= stream_get_contents($pipes[1]);
// leave the loop if the process has already finished
if (!$status['running'])
break;
$timeleft = $end_time - time();
}
if ($timeleft <= 0)
{
proc_terminate($process);
$result = FALSE;
}
}
// check for errors
$errors = stream_get_contents($pipes[2]);
if (!empty($errors))
fwrite(STDERR, "$errors\n");
// close streams
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
return $result;
}
당신이 뭔가를 의미 http://php.net/manual/en/function.sleep.php : 여기
내가 이렇게하고 시간 제한을 적용하는 데 사용하는 기능입니다)? –