How do I limit frequent API calls by clients? There is an http interface on the server. the client initiates a post or get request to call this interface to obtain some data. To restrict the client from initiating requests too frequently, I need to initiate the request at least 60 seconds. Now, I want to record the time when the request was initiated, and then compare the time between the current call and the last call. a status code is returned in less than 60 seconds. In addition to this method, are there other simpler methods? For example, set Apache on the server. thank you for your guidance.
Reply to discussion (solution)
Nothing is simpler than this.
Because you cannot serve only one user. if you limit the service frequency (for example, limit the Apache response)
If there are ten clients, the tenth client will receive a response 10 minutes after the first client request.
This is obviously unreasonable.
Nothing is simpler than this.
Because you cannot serve only one user. if you limit the service frequency (for example, limit the Apache response)
If there are ten clients, the tenth client will receive a response 10 minutes after the first client request.
This is obviously unreasonable.
Access interface: use memcache or redis to record an identifier (such as ip address or user ID) and set the expiration time, such as 60 seconds. when you access the interface next time, you can determine whether this value exists. If no value exists, access is allowed, yes, it indicates that it has not expired, and no access is returned. the memory record should be faster.
I have never touched anything mentioned above. First, let's take a look.
I have never touched anything mentioned above. First, let's take a look.
If you have to implement the function, the third floor provides a good solution.
Write user access interface events to logs and apply corresponding restrictions.