Read last line from file

后端 未结 12 1726
南方客
南方客 2020-12-01 09:13

I\'ve been bumping into a problem. I have a log on a Linux box in which is written the output from several running processes. This file can get really big sometimes and I ne

12条回答
  •  醉梦人生
    2020-12-01 09:59

    function readlastline() 
    { 
           $fp = @fopen("/dosmnt/LOGFILE.DAT", "r"); 
           $pos = -1; 
           $t = " "; 
           while ($t != "\n") { 
                 fseek($fp, $pos, SEEK_END); 
                 $t = fgetc($fp); 
                 $pos = $pos - 1; 
           } 
           $t = fgets($fp); 
           fclose($fp); 
           return $t; 
    } 
    

    Source: http://forums.devshed.com/php-development-5/php-quick-way-to-read-last-line-156010.html

提交回复
热议问题