douchun2158 2014-04-18 18:38
浏览 74
已采纳

PHP文件执行带有连续输出的shell命令

Running shell commands from PHP is done like this:

<?php
$cmd = 'du /';
print shell_exec ( $cmd );
?>

Or

<?php
$cmd = 'du /';
passthru ( $cmd );
?>

However you only see the output when the job is done, how do you get continuous output? The du command above will take a period of time to complete, I'd like to see the output live.

My use case is running the CD ripper and tagger ABCDE, I'd like less technical people to be able to go to a web page to start a rip job but be able to see its progress.

(Lastly, is there a nice way to wrap this with screen or tmux so if the page load terminates the job won't)

  • 写回答

1条回答 默认 最新

  • douzhi3105 2014-04-18 18:47
    关注

    Use proc_open for this. You can then read either stdout or stderr separately as data is being written to the streams.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献