dongyuedaochen8415 2015-05-29 16:19
浏览 26
已采纳

php输出系统()实时

I'm trying to make a system call and have each line sent to the browser in real time

echo('<pre>');
system('ping -c 10 www.google.com');
echo('</pre>);

This works when I call it from the command line (each line of the ping is output one at a time). However it does not work when I try to open with a browser (firefox or chrome).

I am almost certain this has something to do with the output buffering enforced by the browser. They will not display new data unless it is above a cetrain threshold. Solutions to these kind of problems typically involve outputting a bunch of blank characters, ie str_repeat(' ',1024*64). Can you think of any way to get the browser to display the output in real time?

  • 写回答

2条回答 默认 最新

  • dongxi3859 2015-05-29 16:29
    关注

    You can not do it this way. your php request is running once and retrun one response.

    Also the result of system function is shown at the end of the execution of your command. What you see in your command line is only the logs of command it self not your php code.

    I suggest to use a kind of long polling technologies or soquet-io to establish a continues / real time communication with your server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效