我的脚本基本上运行良好,但有时它在 fread 函数调用时停止响应,我似乎找不到失败的原因。
private function run_lengthy_job($command, $message) {
for($handle = popen($command, 'r'); !feof($handle); sleep(2)) {
printf("[%s]\t%s\n", time(), $message);
// log the operation
exec(sprintf('logger "%s"',
escapeshellarg(fread($handle, 1024))));
}
pclose($handle);
}
示例命令
hg clone -v --debug http://some.repository.com/hgwebdir.cgi/some_repo some_repo
现在它在克隆一个大型存储库时失败了。即使我将 fread 更改为 fgets,同样的问题仍然存在。
关于我的php环境的简要信息,
PHP 5.2.4-2ubuntu5.6 with Suhosin-Patch 0.9.6.2 (cli) (built: Apr 17 2009 14:29:38)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
with Xdebug v2.0.3, Copyright (c) 2002-2007, by Derick Rethans
在 ubuntu 8.04.2 上运行
编辑:尝试 proc_open 而不是 popen 并且脚本卡在同一个地方。编辑:用stream_get_contents替换fread,但仍然停留在同一个地方......