用ajax。如果需要跨浏览器兼容性,请使用jQuery之类的库中的AJAX函数替换我提供的AJAX函数。
<html><head></head><body><div id="feed"></div><script type="text/javascript">var refreshtime=10;function tc(){asyncAjax("GET","myphpfile.php",Math.random(),display,{});setTimeout(tc,refreshtime);}function display(xhr,cdat){ if(xhr.readyState==4 && xhr.status==200) { document.getElementById("feed").innerHTML=xhr.responseText; }}function asyncAjax(method,url,qs,callback,callbackData){ var xmlhttp=new XMLHttpRequest(); //xmlhttp.cdat=callbackData; if(method=="GET") { url+="?"+qs; } var cb=callback; callback=function() { var xhr=xmlhttp; //xhr.cdat=callbackData; var cdat2=callbackData; cb(xhr,cdat2); return; } xmlhttp.open(method,url,true); xmlhttp.onreadystatechange=callback; if(method=="POST"){ xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlenpred'); xmlhttp.send(qs); } else { xmlhttp.send(null); }}tc();</script></body></html>您将必须创建一个名为myphpfile.php的php文件(或更改上面的代码以引用正确的文件),并在其中放入以下内容(摘自您的问题):
<?php$filename = '/home/duke/aa/servers/df/var/logs.log'; //about 500MB$output = shell_exec('exec tail -n50 ' . $filename); //only print last 50 linesecho str_replace(PHP_EOL, '<br />', $output); //add newlines?>


