On my site I need to throttle user requests for various reasons:
- Prevent overquerying of database or 3rd party apis
- Prevent spam
- Preventing others from scraping my data
I was wondering what the best practices are for throttling? Should it be done at the script level (PHP/MySQL) or at the server level (Apache)?
And are there any specific best practices I should keep in mind with regards to throttling?
This should ideally be done at the network / firewall level or at the very least on Apache.
PHP throttling is possible too, but it should only be done if you want to deny the access to the resource and not just delaying. Refer to this answer (and comments) I gave in a similar question for more details: