0
我試圖得到一個真正的尾巴-f類型的查看器。通過javascript/jquery尾巴-f實時日誌
http://commavee.com/2007/04/13/ajax-logfile-tailer-viewer/(我得到這個半工作,但它並沒有真正緩衝它)其重寫尾部-20每2秒,而不是真正緩衝它,並使其滾動(需要建立一些東西,最終保存文件,但也是如此,但多數民衆贊成在後),如果我嘗試尾巴-f命令將始終執行,而不是停止
我需要考慮某種類型的obflush *(我試過用ping工具,我正在努力,沒有運氣後天研究output_buffering =關閉在php.ini中設置)*
<?
// logtail.php
$cmd = "tail -20 /usr/local/bin/logs/outages.log";
exec("$cmd 2>&1", $output);
foreach($output as $outputline) {
echo ("$outputline\n");
}
?>
。這是LOGTAIL.JS
function getLog(timer) {
var url = "logtail.php";
request1.open("GET", url, true);
request1.onreadystatechange = updatePage;
request1.send(null);
startTail(timer);
}
function startTail(timer) {
if (timer == "stop") {
stopTail();
} else {
t= setTimeout("getLog()",1000);
}
}
function stopTail() {
clearTimeout(t);
var pause = "The log viewer has been paused. To begin viewing again, click the Start Viewer button.\r\n\r\n";
logDiv = document.getElementById("log");
var newNode=document.createTextNode(pause);
logDiv.replaceChild(newNode,logDiv.childNodes[0]);
}
function updatePage() {
if (request1.readyState == 4) {
if (request1.status == 200) {
var currentLogValue = request1.responseText.split("\n");
eval(currentLogValue);
logDiv = document.getElementById("log");
logDiv.scrollTop = logDiv.scrollHeight;
var logLine = ' ';
for (i=0; i < currentLogValue.length - 1; i++) {
logLine += currentLogValue[i] + "<br/>\n";
}
logDiv.innerHTML=logLine;
//} else
//alert("Error! Request status is " + request1.status);
}
}
}