[英]Display process log on a web page
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.
由于执行过程最多需要10分钟,因此我希望日志页面自动更新自身或定期从文件中加载数据。
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. 到html / head,但想知道是否有更好的解决方案。 Can someone give any advice on aproaching this problem?
有人可以提供有关解决此问题的任何建议吗?
You could: 你可以:
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. 服务器必须在开始时跳过几个字节,并使用current_length和文件的其余部分发送json。
I prefer using memcached to store process output. 我更喜欢使用memcached来存储进程输出。
Use AJAX to do this. 使用AJAX执行此操作。 Easy in jQuery:
在jQuery中简单:
<script type="text/javascript">
$(function(){
window.setInterval('updateLog()', 5000);
});
function updateLog() {
$.get('log.php');
}
</script>
Why not use javascript? 为什么不使用JavaScript?
Use setInterval and run an AJAX call to log.php periodically. 使用setInterval并定期运行AJAX调用log.php。
You could also use an iframe, but the AJAX perdiodical call is a better way of doing it in my opinion. 您也可以使用iframe,但我认为AJAX定期调用是一种更好的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.