Page 1 of 1

Last in, First out, Flat File

Posted: Sun Jul 29, 2007 11:54 am
by shaitand
I am writing a simple download tracker script.

This script keeps a log of downloads with a date stamp. But I don't want to log repeat downloads in the same day.

My problem is that I simply can't find any combination of php file operations that allows first in first out reading of a text file. If I use fputs and fgets or similar then I will have to parse the entire log to get to todays entries which will be at the end of the file. I can't seem to find a way that will let me start parsing the file line by line from the end of the file rather than the beginning. As an alternative appending new entries at the beginning of the file would work but there doesn't seem to be a way to do that either.

There has to be a simple way to do this that I am missing. The only things I can find would require reading the entire file into memory or another file and that would be the slowest possible method. The whole idea is that newer log entries will be accessed more frequently and should be the first parsed, hopefully avoiding parsing the majority of the file.

I do not want to add the overhead of a more complex database and am using file locking.

Re: Last in, First out, Flat File

Posted: Sun Jul 29, 2007 2:35 pm
by shaitand
NM, figured it out.

Posted: Sun Jul 29, 2007 3:38 pm
by Oren
Stop posting the same question over and over :!: