tags:

views:

68

answers:

2

What is the best way to implement the page view counter like the one found here on this site where each question has a "Views" counter using PHP and MySQL??

A: 

I think you should take a look at that discussion, which already covers what you're trying to do. http://stackoverflow.com/questions/1564772/page-views-counter-using-php-and-mysql

You would need to increment a counter in the database every time the page the page is loaded. In the url above, there was a specific table for this counter. But you can only add a "views" field in your post database and increment it the same way.

Damien MATHIEU
A: 

It depends on the amount of traffic your site is getting and in speed.

If you want scalability I'd use caching with a fixed expiration time set and increment values within cache and when cache will get expired a callback would transfer that number to MySQL database. This way things will be scalable and you will save lots of database calls hence speeding up responses.

But I can't advise you on caching in PHP since I'm on MS technologies. Others will provide answer to this.

Robert Koritnik