I have an article-driven website where I would like to display a 'popular post' column using php. I have a php table named 'news' which includes 'id','title','description' etc fields. How can I display my articles/posts according to popularity? Do I need to implement pageview count? What is the best way to do that? I would like to mention that I use MySQL as database and I'm looking for a simple & widely supported solution. Thank you. UPDATE: Could you please clarify what happens when my database freezes due to high traffic? Does my whole site stop working?
-
You first need to define what you mean by "popularity". – Adam Robinson Mar 19 '14 at 19:00
-
This is really too broad. Break it down into multiple questions, and make sure you show your work to date on each. Questions should be around pageview count tracker and ways to display results based on that. Surely you can demonstrate at least what sort of approach you have bee thinking about taking. – Mike Brant Mar 19 '14 at 19:01
-
I'm not sure how other websites rank by popularity. In my case, it could be pageviews,share count etc. The more pageviews a post has,the more popular it is. – Susan Mar 19 '14 at 19:02
-
Mike Brant,I've seen other answers telling me to use a method involving MySQL but then again,a lot of people are complaining that in case of higher amount of visitors,their database is locked up. So,I'm looking for opinions as well as code demonstrations if possible. – Susan Mar 19 '14 at 19:04
-
Are you using raw PHP? What does the code look like which renders your views. – Femi Mar 19 '14 at 19:06
-
@Yitwail,No my site is not on wordpress. I have the seen a few ways to count pageviews involving MqSQL, but I've also heard that it freezes the database.(not sure what they mean).Could you clarify? – Susan Mar 19 '14 at 19:07
-
@MjrKusanagi, Yes I am using raw PHP. And my code is applied every time someone lands on my page. It updates the row $pageview by +1. But is not very effective in case of high amount of visitors. – Susan Mar 19 '14 at 19:09
1 Answers
I think you're interested in a strategy to implement counts while minimizing queries to the database. For medium-intensity php applications, memcache might be the way to go. You can read this other question for more ideas about using memcache.
You can also run a separate process (using cron or something) that will read memcache and write the current value to your standard mysql database. I suggest considering that because this article argues the case that memcache may not be the perfect solution for all your storage needs.
Regarding potential database freezes, this question on ServerFault might provide some insight. The best approach to avoiding this may depend on your storage engine and how you handle atomic commits. This other question about MySql concurrency might be informative.
-
Thanks. Could you please clarify what happens when my database freezes due to high traffic? Does my whole site stop working? – Susan Mar 19 '14 at 19:21
-
Could you add this to your original question? Maybe someone else might have a better answer to that part of your question. – Femi Mar 19 '14 at 19:23