Ryan Cooper
Ryan Cooper

Reputation: 703

Limit curl fetches / refreshes per minute

How would i go about limiting a page refresh and thus curl fetch to one per minute (or 5, etc)? An example would be to pull the price of an item on Amazon, the user is limited to one fetch per minute, after that minute is up he can refresh for an updated fetch, until then he is told to try again in a minute.

Upvotes: 0

Views: 338

Answers (2)

symcbean
symcbean

Reputation: 48387

Just implement a strict set of caching rules - if you get a request for an item, check if its in the cache and not more than N seconds old - if its older, fetch a new one, if its younger send back the cached one. Require a valid session and keep the timestamp of the last accepted request (whether supplied from cache or source). If the user requests additional content before M seconds have expired, then tell them to try later.

Upvotes: 0

AjayR
AjayR

Reputation: 4179

You can store the last fetch timestamp in session for the user. When new refresh requested you need to verify the previous time stamp difference with latest and see the difference is fine or needs to wait.

Upvotes: 4

Related Questions