40 lines
684 B
Markdown
40 lines
684 B
Markdown

|
|
|
|
```PHP
|
|
<?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);
|
|
```
|
|
|
|
```PHP
|
|
function follow($file)
|
|
{
|
|
$size = 0;
|
|
while (true) {
|
|
clearstatcache();
|
|
$currentSize = filesize($file);
|
|
if ($size == $currentSize) {
|
|
usleep(100);
|
|
continue;
|
|
}
|
|
|
|
$fh = fopen($file, "r");
|
|
fseek($fh, $size);
|
|
|
|
while ($d = fgets($fh)) {
|
|
echo $d;
|
|
}
|
|
|
|
fclose($fh);
|
|
$size = $currentSize;
|
|
}
|
|
}
|
|
|
|
follow("file.txt");
|
|
``` |