Re: Overwriting specific lines in text files without rewriting the whole thing.
| From: | Paul DuBois | Date: | Mon, 26 Jun 2000 21:00:44 +0000 |
| Subject: | Re: Overwriting specific lines in text files without rewriting the whole thing. | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3204@lists.php.net to get a copy of this message | ||
At 4:22 PM -0400 2000-06-26, John Biesnecker wrote:
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.You might consider using a table in a database for this. All you need is a table with a count field and a unique field that associates with your pages (one easy thing is to use the URL of the page for the table key). Using a database will allow you to update any row independently of any other. -- Paul DuBois, paul@snake.net