How to Implement the number of today's topics

Source: Internet
Author: User
That is, how does one achieve the number of posts on the forum today? Is it true that php automatically clears the number of posts in the database at today? Is there any code for the Forum? Is there a general number of posts on the forum today? is it true that php automatically clears the number of posts in the database at today?

Reply content:

That is, how does one achieve the number of posts on the forum today? Does php clear the number of posts sent in the database at automatically? Is there any code for the segment?

It depends on your requirements. For example, if the number of posts in a small forum is small, you can use SQL to query the number of posts on the day.

select count(*) from item where created_at >= curdate();

However, if there are more users and more posts, real-time computing is always performed, and the performance is poor, you can create a table. When a user posts a new post, the number of posts will increase by 1.

Create table topics_num (created_date date, num int, primary key (created_date); -- Query select num from topics_num where created_date = curdate ();

However, when there are more users and more posts, the database is always to be queried, and the performance is poor, and the number of concurrent jobs is incorrect. In this case, a faster computing method is required to use the cache, for example, redis

$ T = new DateTime ('today'); $ key = 'topics _ num _'. $ t-> format ('Y-m-d'); // when someone sends a new post $ redis-> incr ($ key ); // when you need to obtain the quantity, $ redis-> get ($ key );

There are multiple implementation methods.
Redis, text, and SQL are all OK

Write a scheduled task

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.