dongliang1996 2015-05-02 13:43
浏览 31

使用Ajax在PHP中运行函数时显示实时调试消息

I have a function like this that may run for 20 minutes:

function  test($videoarray)
{
    for($i;$i<100;$i++)
        if(converVideo($videoarray[$i]))
        {
           echo 'video number '.$i.' has been convert';
        }
        else
        {
           echo 'video number '.$i.' Is too large.';
        } 
}

During this time I wish I could see the messages live, for example with Ajax/PHP.

Is it possible?

Desired result:

1st min:  video number 1 has been converted.
2nd min:  video number 2 is too large.
,
.
.
  • 写回答

1条回答 默认 最新

  • dream_wu2015 2015-05-02 13:57
    关注

    I would recommend adding flush(); after each echo

    This should force the message to the screen once written.

    Example

    echo 'video number '.$i.' has been convert';
    flush();
    

    PHP FLUSH

    This might not always work therefore one can always persist the messages to a database and have a polling mechanism to read the message every couple of seconds.

    EXAMPLE of PHP Polling

    评论

报告相同问题?

悬赏问题

  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器