Question

i have a blog system which has articles inside a database, now i want to build a feature where it displays five of the most popular articles in the database, according to how many views it gets. Is there any sort of technology out there which i can take advantage of where it states how many views a page has received, and IS able to be integrated into a database.

Or perhaps there is a better internal method of doing something like this?

Thanks in advance.

EDIT: If you are going do down vote my thread randomly, at least tell me why.

Was it helpful?

Solution

You have three choices as an approach for this obviously:

  • you collect the usage count inside your database (a click counter)

  • you extract that information from the http servers access log file later

  • you could implement a click counter based on http server request hits

Both approaches have advantages and disadvantages. The first obviously means you have to implement such a counter and modify your database scheme. The second means you have asynchronous behavior (not always bad), but the components depend on each other, so your setup gets more complex. So I would advise for the first approach.

A click counter is something really basic and typical for all cms/blog systems and not that complex to implement. Since the content is typically generated dynamically (read: by a script) you typically have one request per view, so it is trivial to increment a counter in a table recording views of pages. From there your feature is clear: read the top five counter values and display a list of five links to those pages.

If you go with the second approach then you will need to store that extracted information, since log files are rotated, compressed, archived and deleted. So you either need a self tailored database for that or some finished product. But as said: this approach is much more complex in the end.

The last option is nothing I saw, it just sprang to my mind. You could for example use phps (just as an example) auto append feature to run a counting routine in a generic way. That routine could interpret the request url, decide if it was a request to an article view. If so it could raise a click counter, typically in a small database, since you might have several requests at the same time, which speaks against using a file. but why make things that xomplex? Go with the first option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top