Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

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?

Avatar of j-a-c-k
j-a-c-kFlag for United States of America asked on
2 Comments1 Solution325 ViewsLast Modified:
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??
Avatar of Hugh Fraser
Hugh FraserFlag of Canada imageConsultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers