Laravel queue rate limiting or throttling

后端 未结 6 1309
南方客
南方客 2020-12-11 17:19

I am working on an app that requires fetching data from a third-party server and that server allows max 1 request per seconds.

Now, all request send as job and I am

6条回答
  •  失恋的感觉
    2020-12-11 17:55

    Assuming you have only single worker you can do something like this:

    • do what has to be done
    • get time (with microseconds)
    • sleep time that is 1s minus difference between finish time and start time

    so basically:

    doSomething()
    $time = microtime(true);
    usleep(1000 - ($time - LARAVEL_START));
    

提交回复
热议问题