Re: Overwriting specific lines in text files without rewriting the whole thing.
| From: | Carroll Barrett | Date: | Mon, 26 Jun 2000 21:02:39 +0000 |
| Subject: | Re: Overwriting specific lines in text files without rewriting the whole thing. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3200@lists.php.net to get a copy of this message | ||
John,
You might consider having a separate counter file for each page,
if you don't have too many pages.
Regards,
Carroll Barrett
-----Original Message-----
From: John Biesnecker <amraam@ao.net>
To: php-general@lists.php.net <php-general@lists.php.net>
Date: Monday, June 26, 2000 3:48 PM
Subject: [PHP-GENERAL] Overwriting specific lines in text files
without rewriting the whole thing.
I have created rather simple file-based page hit counter for my
site (because I can't use SQL or anything else). Currently I am
reading the entire thing into an array using file(), finding the
correct line, editing it and writing the entire thing back into a
file.
After a few weeks of content development, however, my counter
data file has gotten very large, and reading and writing the
entire file is beginning to take a noticable amount of time. I'm
already sorting the file so the most accessed pages are on top,
hoping to reduce time needed to find the correct entry.
I'm wondering if there is a way that while reading the file line
by line and I can alter a single line and write it back to the
file without disturbing the rest of the lines and then exit.
Also, if there is, will I see any performance improvement worth
the code rewrite.
Thanks.