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