[Wolves] Echoing first and last line of large file in PHP
drinky76 at yahoo.com
Fri Mar 25 19:10:23 GMT 2005
Hi all, not a Linux question as such but...
I need to strip out the first and last line of a 500MB
Apache log file for an assignment, so I can then
explode it and echo the first date entry and last date
Being as large as it is, I can't use an array as it
will eat all of the server memory and it takes >30
seconds to parse the file (this is on a live server).
Is there a quick way of doing this like the Unix head
and tail commands?
I've looked at fgets but can't see how to specify the
first and last lines and fseek which while I can set
the file pointer to the beginning and the end of file,
I don't know how many bytes to read forwards from the
beginning or backwards from the end as each line is a
I assume that I have either overlooked something
simple or am looking at this the wrong way. I have the
O'Reilly PHP Cookbook and Programming PHP books. There
is an example on P475 for removing the last line of a
file without using and array, but it seems a large
piece of code for such a simple operation and I don;t
understand it very well.
Any help is appreciated. Either that or I'm going to
phone Jono ;)
Send instant messages to your online friends http://uk.messenger.yahoo.com
More information about the Wolves