Page 1 of 1

Burden to open and append text file with fopen

Posted: Tue Feb 03, 2009 12:54 pm
by john1in2
Hello!

Thanks to your help, I wrote a small php script using fopen (...,'a'); fwrite and fclose to write the IP address of visitors to my web site into a text log file.

viewtopic.php?f=1&t=93484&p=511298#p511298

Its been working great but now my file is approaching 200K.

My question for your theorists is....is there a cost to having php open and append text files when they get large? Will it slow down my site or can I just continue on as the thing gets up to a few MB?


- thanks

Re: Burden to open and append text file with fopen

Posted: Wed Feb 04, 2009 1:17 am
by josh
Creating a handle is relatively inexpensive. Seeking a couple times is inexpensive, but lots of seeking would be expensive. Reading small amounts of data would be inexpensive reading large amounts would be expensive. Same with writing small amounts of data. appending involves creating a handle, seeking 1x to the end of the file, and then writing some data and closing a handle.

Re: Burden to open and append text file with fopen

Posted: Wed Feb 04, 2009 8:58 am
by Jenk
If all you are doing is appending, I'd be tempted to just do:

Code: Select all

shell_exec("echo " . escapeshellarg($ipAddress) . " >> /path/to/file.txt");