Tail a text file on a web server via HTTP

被刻印的时光 ゝ 提交于 2019-12-05 08:14:18

You can you the following PHP script:

<?php
header("Content-Type: text/plain");
set_time_limit(0);
passthru("tail -F -n +0 log.txt");
?>
orangepips

The following psuedo-code is inspired by this Java solution and has not been tested at all:

if (NOT structKeyExists(application, "log") {
    application.log = fileOpen('log.txt', 'read')
}

while(NOT FileisEOF(application.log))  {
    writeOutput(fileReadLine(application.log) & "<br/>");
}

Put that on a page with a meta refresh and I think you are probably in business.

I create the following bash script for my use case (tail.sh)

It with using 'lynx' get list of files from which get filesize that needed, and in infinity loop trying to get part of file

I know it's pretty old school, but have you considered logging to a database? If you timestamp the log entries in the table you could use HTTP Caching headers to communicate to the server what new data you should see.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!