Cgi Counter

Nomad nomad*** at ***freemail.absa.co.za
Wed Oct 17 06:35:01 EDT 2001


On 16 Oct 2001 15:05:37 +0100, Dominic Mitchell <dom at semantico.com>
wrote:

>Paul Rubin <phr-n2001d at nightsong.com> writes:
>> Nomad <nomad***@***freemail.absa.co.za> writes:
>> 
>> > On Fri, 12 Oct 2001 12:59:04 -0700 (PDT), Neal Irwin
>> > ...> 
>> > fileWrite = open('count.txt', 'w')
>> > fileWrite.write(str(intHits))
>> > fileWrite.close
>> > ...
>> > Pretty simple, but it works...
>> 
>> Um, what happens if two requests (coming from different processes in
>> the web server) run the hit counter at the same time?  You need some
>> kind of interlocking for this to be reliable.
>
>Alternatively, if you don't mind losing the occaisional hit, you could
>just write to a temp file and rename into place.  Renaming is an
>atomic operation (under Unix, anwyay, dunno about win32), so you won't
>get corruption, just a few lost hits.
>
>-Dom

Thanks for the hints.  At the time it was a two-minute-solution, and,
as the site wasn't very high traffic, it worked.  For the site in
question hits weren't particularly important, but just there to show
the other visitor that there was interest in the conference.

I'll definitly bear file contention in mind if I need counters again
in the future.

-- 
Nomad

Wondering of the vast emptyness of the 'net
in search of something cool.



More information about the Python-list mailing list