There is a way that I use.
Method 1: (File Size) Each time someone hits the page, I add another byte to the file. Then after x seconds or so (I set 600), I will count how many bytes in my file, delete my file, and then upgrade it to the MySQL database. It will also scale if multiple servers are added to a small file on the cache server. Use fwrite to add to the file and you will never have to read this cache file.
Method 2: (The number stored in the file) Another method is to save the number in a text file that contains the number of hits, but I recommend using it, because if two processes are updated at the same time, the data may be disabled (maybe the same thing with method1).
I would use method 1, because although this is a larger file size, it is faster.
source share