PHP limit a certain amount of query per day, how to achieve it?
Reply content:
PHP limit a certain amount of query per day, how to achieve it?
Upstairs positive solution.
If it is a single-user limit query volume , cumbersome method is to write into the database, ascending, 12 o'clock Zero, clear 0 here may need to use the scheduled task.
A good way to do that is to 用户ID+标识
key
write into Redis.
If the limit is not based on a single user, but based on the total number of queries to limit, in addition to the above two methods are written into the text file, when used,,, 读取
比较
+1
写入
In fact, the combination of the above, nothing but the action is,,,, 取值
比较
but the media is +1
写入
not the same, depending on the demand.
Yes, it can also be used with timed tasks if needed.
Simply put, that is the query once a write. There is no difference between the principle of human restriction and inquiry.
Basic idea: Query once, database increment once.
A large amount of query performance will naturally suck.
It's like Redis, and every increment is cached into memory to improve efficiency. Updated at intervals/a certain number of times