Home  >  Article  >  Backend Development  >  PHP limits a certain number of queries every day. How to achieve this?

PHP limits a certain number of queries every day. How to achieve this?

WBOY
WBOYOriginal
2016-12-01 00:25:32976browse

php limits a certain number of queries every day, how to achieve it?

Reply content:

php limits a certain number of queries every day, how to achieve it?

Correct answer upstairs.
If it is limiting the query volume for a single user, the cumbersome method is to write it into the database, increment it in sequence, and clear it at 12 o'clock in the evening. A scheduled task may be used to clear it.
A good way is to use user ID+identification as key and write it into redis.
If it is not limited based on a single user, but based on all query volume, in addition to the above two methods, there is another way to write into a text file. When used, read, compare, +1,write

In fact, based on the above, the only required actions are get value, compare, +1, write, but the medium is different, it depends on the needs.
By the way, it can also be used with scheduled tasks if necessary.

Simply put, it means one query and one entry. There is no difference in principle from human restricted query.

Basic idea: Query once and increment the database once.

When the query volume is large, the performance will naturally be poor.

Then use Redis or the like, and cache it into the memory first for each increment to improve efficiency. Updated as a whole every once in a while/a certain amount

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn