简体   繁体   English

页面浏览计数器是否像StackOverFlow上的计数器一样?

[英]Page View Counter like the one here on StackOverFlow?

像在本网站上找到的那样,实现页面视图计数器的最佳方法是什么?使用PHP和MySQL,每个问题都有一个“视图”计数器?

I think you should take a look at that discussion, which already covers what you're trying to do. 我认为您应该看看该讨论,该讨论已经涵盖了您要进行的操作。 Page Views counter using PHP and MySQL? 使用PHP和MySQL的网页浏览量计数器?

You would need to increment a counter in the database every time the page the page is loaded. 每次加载页面时,您都需要在数据库中增加一个计数器。 In the url above, there was a specific table for this counter. 在上面的网址中,该计数器有一个特定的表。 But you can only add a "views" field in your post database and increment it the same way. 但是您只能在帖子数据库中添加一个“视图”字段,并以相同的方式增加它。

It depends on the amount of traffic your site is getting and in speed. 这取决于您的网站获得的流量和速度。

If you want scalability I'd use caching with a fixed expiration time set and increment values within cache and when cache will get expired a callback would transfer that number to MySQL database. 如果您想实现可伸缩性,我将使用具有固定到期时间设置和缓存中增量值的缓存,并且当缓存将过期时,回调会将该数字传输到MySQL数据库。 This way things will be scalable and you will save lots of database calls hence speeding up responses. 这样,事情将具有可伸缩性,您将节省大量数据库调用,从而加快响​​应速度。

But I can't advise you on caching in PHP since I'm on MS technologies. 但是由于我使用的是MS技术,因此我不建议您使用PHP进行缓存。 Others will provide answer to this. 其他人将对此提供答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM