douxun2023 2010-07-15 10:18
浏览 154
已采纳

在网页上显示进程日志

I've got a web page that allows to start a certain process and then redirects to another page that displays log file of that process. Since execution takes up to 10 minutes, I want log page to autoupdate itself or load data from the file periodically.

Right now I added

<meta http-equiv="refresh" content="5;url=log.php#bottom" /> 

to html/head but wondering if there may be a better solution. Can someone give any advice on aproaching this problem?

  • 写回答

4条回答 默认 最新

  • douwen5690 2010-07-15 10:49
    关注

    I do it this way:

    var current_length = 0;
    function update() {
      setTimeout(update, 3000);
      $.post("/update_url", { 'current_length': current_length }, function(data) {
        if (data.current_length != current_length) return; //it's too old answer
        $("#log").html($("#log").html() + data.text);
        current_length += data.text.length;
      }, "json"); 
    }
    update();
    

    The server must skip several bytes at beginning and send json with current_length and the rest of file.

    I prefer using memcached to store process output.

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

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧