What is the best way to count page views in PHP/MySQL?

后端 未结 8 754
[愿得一人]
[愿得一人] 2020-12-07 09:47

And by best I mean most efficient, right now placing this on my post.php file is the only thing I can think of:

$query = mysql_query(\" UPDATE posts SET view         


        
8条回答
  •  感情败类
    2020-12-07 10:31

    You could keep a counter-array in cache (like APC or Memcache) and increase the counter for certain posts in that. Then store the updates once a while. You might loose some views if a cache-reset occures

    Other solution would be to keep a separate table for visits only (Field: postid, visits). That is the fasters you can get from mysql. Try to use InnoDB engine, since it provides row-level-locking!

提交回复
热议问题