更新文件的实时馈送

我有一个php文件打印txt文件的最后50行。 但是,此文件每秒都会被追加,并且希望查看该操作的“实时提要”。 如何才能做到这一点? 这是php文件的代码:

<?php $filename = '/home/duke/aa/servers/df/var/logs.log'; //about 500MB $output = shell_exec('exec tail -n50 ' . $filename); //only print last 50 lines echo str_replace(PHP_EOL, '
', $output); //add newlines ?>

用ajax。 如果您需要跨浏览器兼容性,请将我提供的AJAX函数替换为jQuery等库中的函数。

  

您将不得不创建一个名为myphpfile.php的php文件(或更改上面的代码以引用正确的文件)并在其中添加以下内容(从您的问题中获取):

 ', $output); //add newlines ?> 

检查使用PHP,在PHP中读取高效的最后一行文件

http://mydebian.blogdns.org/?p=197

要么

如果在服务器上安装了tail,那就快了

 $logfile = '/home/duke/aa/servers/df/var/logs.log'; $numlines = "50"; $cmd = “tail -$numlines '$logfile'”; $output = shell_exec($cmd); echo $output;