<?
function tail($file,$n,$base=5){
assert($n>0);
$pos = $n+1;
$lines = array();
$fp = fopen($file,"r");
while(count($lines)<=$n){
try{
fseek($fp,-$pos,SEEK_END);
}catch(Exception $e){
fseek(0);
break;
}
$pos *= $base;
while(!feof($fp)){
array_unshift($lines,fgets($fp));
}
}
return implode('', array_slice($lines,0,$n));
}
echo tail('log/access.log', 10);