Last in, First out, Flat File

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Locked
shaitand
Forum Newbie
Posts: 10
Joined: Sun Jul 29, 2007 9:54 am

Last in, First out, Flat File

Post by shaitand »

Sorry if this is the wrong place to post this but I have been unable to get a response elsewhere.

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.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Double Posting

Post by hawleyjr »

Please do not double post.

viewtopic.php?t=71487


[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:3. Do not make multiple, identical posts. This is viewed as spam and will be deleted.
Locked