4

How to Tail a File with PHP

 3 years ago
source link: https://www.devdungeon.com/content/how-tail-file-php
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Tail a File with PHP

Submitted by NanoDano on Mon, 07/27/2015 - 19:45

This code will allow you to tail a file in PHP. It is cheating a little bit though because it is actually making a system call to tail, so you have to have tail installed. It is meant for Linux machines not Windows.

<?php
$handle = popen("tail -f /etc/httpd/logs/access.log 2>&1", 'r');
while(!feof($handle)) {
    $buffer = fgets($handle);
    echo "$buffer<br/>\n";
    ob_flush();
    flush();
}
pclose($handle);
Tags: 

Advertisement


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK