How can php limit the number of queries per day? How can php limit the number of queries per day?
Reply content:
How can php limit the number of queries per day?
Upstairs.
If yesLimit the number of queries per userThe cumbersome method is to write data into the database, which increases sequentially and is cleared at PM. the scheduled task may be used here.
A good method isUser ID + ID
AsKey
Write it into redis.
If it is not based on a single userTotal queriesIn addition to the above two methods, there is also a way to write into the text file, when usedRead
,Comparison
,+ 1
,Write
In fact, what we need to do isValue
,Comparison
,+ 1
,Write
But the media is different, depending on your needs.
By the way, you can also use it with scheduled tasks if necessary.
Simply put, it is to record a query at a time. There is no difference in the principle of human restricted queries.
Basic idea: query once and database increments once.
When the query volume is large, the performance is naturally bad.
So we can cache Redis and so on, and cache them to the memory at a time to improve efficiency. Update at intervals/a certain number of times