Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best view count strategy

I am currently storing each view in database with user IP, view date etc. But mine website has large number of hits and it is increasing the database locking time and decreasing performance.

I was thinking to save the counts in a file for 1 hour and then update the database but somebody told me that we don't use file operations for heavy load sites.

Please suggest me best strategy to do this.

Note: I don't need to count the unique views.

like image 807
Lalit Arora Avatar asked Nov 13 '22 07:11

Lalit Arora


1 Answers

Your webservers logs will already be tracking much of this data for you.

What I'd suggest is rotating the logs once an hour and then have a scheduled job that produces the aggregate stats and stores them in the DB.

like image 155
Andy Davies Avatar answered Dec 10 '22 03:12

Andy Davies