5
Through the Shell
, I can display the last 5 lines of a file through the command tail
.
Thus:
> tail -n 5 public/index.php
I would like to do the same thing in PHP. But I didn’t want to load the whole file, but really only display the last 5 lines.
I know it’s possible to display the first five like this:
$f = new SplFileObject('public/index.php');
$f->rewind();
for ($i = 0; $i < 5; $i++) {
echo $f->fgets();
}
But how can I display the last 5 lines of a file while maintaining good performance?
Observing: I don’t want a solution where you have to open the command line via PHP.
:I hope there’s an easy way to do this.
– rray
performance or performance?
– Pedro Sanção
Eiu always getting confused.
– Wallace Maxters