问题描述
如何为可能会运行很长时间的shell命令提供反馈?
how can I provide feedback for a shell command that may run for quite some time?
例如,我需要执行hg clone的脚本...然后在我的php中我打电话
for example, i need a script that does hg clone ... then in my php i make a call
exec('hg clone ...', $output, $return_value);
但是在命令实际结束之前我将无法获得输出.它在文档中进行了说明( http://www.php.net/manual /en/function.exec.php )
but I wouldn't be able to get the output before the command actually ends. It is stated in the documentation ( http://www.php.net/manual/en/function.exec.php ) that
Note: If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.
这意味着我应该将命令更改为类似于
would it mean I should change my command to something similar to
exec('hg clone 2>&1 $some_file', $output, $return_value);
我是否需要在命令后面加上&符号才能使其在后台运行?我可以使用$ some_file信息向用户提供反馈吗?
do I need the ampersand symbol at the back of the command to make it work in background? and can I use information $some_file to provide feedback to the user?
推荐答案
popen:
PSpopen可以与AJAX配合使用
PSpopen works fine with AJAX
这篇关于PHP长时间运行的脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!