gowork/throttler

Sleep

PB opened this issue · 1 comments

PB commented

usleep($microseconds);

In my opinion it is not good idea to use sleep (usleep). You are wasting a webserver thread while your are sleeping. Also, if you sleep for too long either server will kill your process as stuck or user's browser will time out and give up. You also opening yourself up wide open to a trivial DoS attack.

dazet commented

You are right, it is not a good idea to throttle web requests in PHP, there are better tools or services for that need. We didn't even think that someone would use Throttler for this.

However, Throttler can be helpful in console commands that:

  • downloads lots of data from API that has rate limiting and bans for too many request per second
  • clogs queues or databases with too many tasks per second.

Maybe there more efficient ways than sleep, but in most cases its easier that way as it doesnt require any infrastructure (like queues).