I am working on a PHP script that needs to read log files in reverse line order.
I currently do the following:
<?php
shell_exec("tac logfile.log > tmpfile.log");
$rFile = fopen("tmpfile.log", "r");
while (!feof($rFile))
{
//logic
}
unlink("tmpfile.log");
?>
This works nicely as it switches the order of the lines in the file and I read from the temp file.
However, the log files are going to get massive and I need to keep a lengthy history, so I need to g开发者_开发问答zip the files up. I found out about 'zcat', and I was hoping that there would be 'ztac' which could plug straight into my code above... but I haven't managed to find it.
Any ideas what the easiest/best way to do this is without needing lots of temp files and a big mess of server commands?
I'm thinking
zcat logfile.log.gz | tac > tmpfile.log
Unzip and reverse lines as two steps.
精彩评论