j-a-c-k
asked on
This solution is good until the file gets too big. How would you recommend creating a wrap around file . That would store only the last 1000 entries?
Keeping information in a log file with PHP seems easy until one realizes that the log will continue to grow.
There seems to be no easy way to simply move the pointer back to the top of the file without truncating the file.
All examples that I can find revolve around one of two methods:
The first method is to start by writing the new log record to a new file, then read in the records one at a time from the old file writing them back to a new file until you have written as many as you want to maximize the log.
The second method is to suck the entire file into memory, plunk the new record in front of it, wack off the excess and write it back to disk.
Method one uses two files and can use lots of time.
Method two uses lots of memory
Is there a best practice here??
There seems to be no easy way to simply move the pointer back to the top of the file without truncating the file.
All examples that I can find revolve around one of two methods:
The first method is to start by writing the new log record to a new file, then read in the records one at a time from the old file writing them back to a new file until you have written as many as you want to maximize the log.
The second method is to suck the entire file into memory, plunk the new record in front of it, wack off the excess and write it back to disk.
Method one uses two files and can use lots of time.
Method two uses lots of memory
Is there a best practice here??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
another alternative may be logrotate (linux).