views:

168

answers:

4

I have a site where I want to record how many unique views an entry gets. At the moment I'm storing each view in a table (see below) but I can't help feeling this is too heavy handed.

+--------+---------------+
| postid |  remote_addr  |
+--------+---------------+
|   1    |  192.168.0.0  |
|   2    |  127.0.0.1    |
+--------+---------------+

Obviously this requires at least one query per page, in addition to the rest of the page content, so is there a simpler/lighter way of doing this?

+2  A: 

Is this something you can get from your web logs? If it is, you can just get a log parser and filter your pages, and unique visitors.

AaronS
This does sound like an interesting solution an automated script could take care of.
Ross
+2  A: 

This is something that I've tried to do in the past, and gave up in favor of just letting my log analyzer do what it's good at. When I did do it, I used the technique you're describing. It didn't incur much overhead, but I did have to write all of my own logic for reporting and filtering bots...not fun.

I'll also point out that just storing an IP address isn't going to guarantee that you're recording uniques. It's not uncommon for your visitors to be coming from behind a proxy (especially AOL I've noticed in years past).

Boden
I'm debating limiting views to actual userids but this only counts logged in users. I think IPs are probably good enough for now.
Ross
+1  A: 

I strongly suggest you use Google Analytics or any other similar tool, that gives you a very good report and detailed statistics about your visitors.. unique visits, time on site, returning visitors, etc.

It's also easy to install, you just add some javascript code you get on that site.

Stiropor
I do use that but this is for publically displaying the view count, such as on Stack Overflow.
Ross
Than afaik this is the easiest way, just use sessions and cookies to make sure you don't count someone twice. One query will be wasted, but unless you have more than 500.000 pageviews daily, it shouldn't be so horrible :)
Stiropor