S
S
Salavat Sitdikov2014-07-09 09:31:48
Nginx
Salavat Sitdikov, 2014-07-09 09:31:48

How to make an article view counter?

Good afternoon everyone.
The task is to have a website, media. We count the number of views for each article. There is no problem on the idea, except for one - the front is nginx, which caches pages and gives static, and a ready-made html page.
What is the best way to count views in this case? The option with parsing access logs is in the very last place.
One option is an ajax request after the page is loaded. All data is written to the MEMORY table and is entered into the main table by cron every n minutes.
What else can you offer?
TOTAL

After listening to the advice, I decided to do the following. Since all articles start with /article/ - create a location for it in nginx and register a separate access log with the formatting I need and cron to get real page views from it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Entelis, 2014-07-09
@zona7o

You actually answered all the questions yourself :)
1. External statistics. For example Yandex.metric. There is an API api.yandex.ru/metrika from which you can easily get everything.
Plus of the solution - no additional load
Minus of the solution - to calculate the statistics of the mobile application,
you will have to pervert well no need to load the main sql server.
The plus of the solution is that you can monitor anything.
The minus of the solution is an extra load on the backend. I don't know how many views you have, but it could potentially be quite a lot.
Another disadvantage - without additional logic on the server - it is easy to wind up the counters.
3. Parsing access logs is actually the right decision. From the point of view of business logic, realtime updating of counters is not necessary (especially if you have a static cache in front), so you can safely read statistics in the background, saving aggregated data to the database every nn seconds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question