Looking for a PHP solution to:
- Perform ‘tail’ type shell command on a file
- Perform ‘tac’ type shell command on a file
In other words, display the last lines of a file in reverse order, from last to first, like a log reader.
I just asked this question for Bash, hoping I could run a shell_exec(), but the recommended method – tac – doesn’t work on my OSX.
Take a look at http://php.net/manual/en/function.array-reverse.php
A non-efficient way would be to fgets() the whole file into an array and then reverse it (Not good on big files).
OR
http://tekkie.flashbit.net/php/tail-functionality-in-php