We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Request Throttling

Hi,

I'm not sure if I've classified this correctly or not, but I'm looking for some input on request throttling. With laravel I've noticed it's rather simple to limit the number of requests to a particular page, however, I've yet to see any ideas on accomplishing this with phalcon.

Any input or advice is more than appreciated.

Thanks.

Well, IMHO that shall be handled elsewhere, not your app. Your app will spend too much resources to handle that when under heavy load, and often those "solutions" fail miserably.

App should be handling (only) business logic.

You'd need to provide more information - perhaps your case could be KISS one, thus achieavable on app side of things.



3.7k
edited May '18

I don't oppose it, but at least looking through the examples, it looks like it requires redis which I am trying to keep my project as simplistic as I can. If it seems to be the only solution I will definitely consider it then.

Why not this?

https://github.com/oak-labs-io/phalcon-throttler

You will have to manage the list of IPs and request counts somehow, and DB is just way too slow for that.

You could use files, but then again you will have scalability issues, and if you need throttling that means you want to scale, so I wouldnt go down that path either.

Imo some kind of memory queue (redis/rabbitmq/elastic) is a MUST nowadays. If you install redis, you can use it as a session adapter and caching backend within phalcon.



85.5k
edited May '18

seems strange that you try to keep your projects simple, but you you want to add a throttler :D anyways, i think me and everybody else are using fail2ban. But its annoying thing to maintain, my service is disabled and ready on stand by, only if needed than i would enable it. I feel like those kind of optimisations are overkill. The only place i use this kind of a feature is on wrong user/pass if the request is from same IP i sleep for 2/4/8/20 secs.based on number of tries