Sign in to follow this  
Daniel Miller

php counter using mysql

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this