Here is a simple way to get the last line of a file without reading the entire file into memory.
Use Linux’s Tail command to get last line of a file.
$file = escapeshellarg( '/home/bin/somefile.txt' ); $last_line = `tail -n 1 $file`;
Here is a PHP fseek function that utilises a dynamic buffer which is more efficient than
tail on larger files – https://gist.github.com/lorenzos/1711e81a9162320fde20