php-crud-api icon indicating copy to clipboard operation
php-crud-api copied to clipboard

Add rate limit functionality

Open mhajder opened this issue 7 years ago • 10 comments

Hi, Can I use rate limit with php-crud-api? And how can I create this rate limit.

mhajder avatar Aug 27 '17 19:08 mhajder

No, that is not (yet) supported.

You can run the script behind Kong. See: https://getkong.org/

mevdschee avatar Aug 28 '17 06:08 mevdschee

Is there something for shared hosting?

mhajder avatar Aug 28 '17 08:08 mhajder

@Rzeszow do you have memcache available? You need some store and should preferably not be the database or disk (for performance reasons).

mevdschee avatar Aug 28 '17 10:08 mevdschee

Yes i have.

mhajder avatar Aug 28 '17 10:08 mhajder

You can do something like described here:

https://www.leaseweb.com/labs/2015/06/limit-concurrent-php-requests-using-memcache/

mevdschee avatar Aug 28 '17 13:08 mevdschee

Thanks

mhajder avatar Aug 28 '17 13:08 mhajder

Some Design ideas:

If you exceed the provided rate limit for a given endpoint, you will receive the 429 Too Many Requests response

Rate limits should allow filtering of concurrent requests per ip address.

Rate limits should allow a bucket per "concurrent", "minute", "hour" and/or "day"

mevdschee avatar Oct 08 '18 15:10 mevdschee

Rate limit scopes should be "per authenticated session" (a specific session key), or "per ip address"

Rate limits may have different buckets for different endpoints.

Rate limits may set 'X-Rate-Limit' headers, see: https://tools.ietf.org/id/draft-polli-ratelimit-headers-00.html#rfc.section.3.1

mevdschee avatar Mar 24 '21 08:03 mevdschee

We could count query/server time and limit the quota to x milliseconds execution time per hour, to make the quota fairer.

mevdschee avatar Mar 24 '21 09:03 mevdschee

rate limiter should error with: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429

maybe a 'Retry-After' header (seems similar to X-Rate-Limit-Reset)

mevdschee avatar Mar 24 '21 09:03 mevdschee