Hello,
I'm very new to PHP. I'm trying to view just the last 50 entries to my log files. I know I have to use a tail command but how?
I can open my access_log with:
<?php
$text = "/var/log/httpd/access_log";
if(!($fp = fopen($text, "r"))) die ("Cannot open $text");
echo "Log File<br>";
fpassthru($fp);
?>
but of course it tries to print the whole file. A script I found uses `tail, but I get a safe mode error with that.
I found this script, but it just returns a blank screen. How do I make the tail work?
<?
$erfile = "/var/log/httpd/access_log";
$lines = 50;
exec("tail -$lines $erfile",$arr);
print "<HTML><BODY><PRE>";
for ($i=0;$i<count($arr);$i++) print "$arr[$i]\n";
print "</PRE></BODY></HTML>";
?>