php counter using mysql

Started by
1 comment, last by Daniel Miller 17 years, 4 months ago
I'm trying to write a very simple hit counter in php. No data is stored other than the count itself. Several tutorials I've seen involve writing/reading from a data file. I can imagine this would break if two visits occur at the same time (they both read the same value from the data file and both write the same updated value). I've also seen a similar approach using mysql, with the same problem (I assume...). Is there any other way other than adding another row to a table for each visit?
Advertisement
Locks are generally used to prevent concurrent updates. A locked object (file, table) cannot be read or written by another process, so one would lock the object, read/write the necessary data, and unlock it.
Thanks for the response, I think I'm just going to add rows to a table. That way, I can use an auto-incrementing field to keep count, and I can periodically clear the table to keep if from getting ridiculously big.

This topic is closed to new replies.

Advertisement