php 使用fseek指针读取大文件日志

function text($fp,$n,$b=5)
{
    if($n>0){
    $p = $n+1;
    $lines = array();
    while(count($lines)< =$n){
        try{
/SEEK_END - 设定位置为文件末尾加上 要移动到文件尾之前的位置,offset 必须是一个负值 / fseek($fp,-$p,SEEK_END);//$p 必须为负值 } catch (Exception $e){ fseek(0); break; } $p *= $b; while(!feof($fp)){ array_unshift($lines,fgets($fp));//插入$lines 数组里 } } return array_slice($lines,0,$n);//
}
}
posted @ 2017-03-10 00:25  未解  阅读(312)  评论(0编辑  收藏  举报