Read last line from file

后端 未结 12 1735
南方客
南方客 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:45

    Untested code from the comments of http://php.net/manual/en/function.fseek.php

    jim at lfchosting dot com 05-Nov-2003 02:03
    Here is a function that returns the last line of a file.  This should be quicker than reading the whole file till you get to the last line.  If you want to speed it up a bit, you can set the $pos = some number that is just greater than the line length.  The files I was dealing with were various lengths, so this worked for me. 
    
    

提交回复
热议问题