1

I've a code base written in Laravel 9 which targets to execute multiple requests to one API with 1000 different API keys + API secrets. Is there a way to actually do this simmultaniously and not one after another ? I've come up to this thread Laravel Commands, Pthreads and Closure but the answer there doesn't look like it is wokring, in my opinion it shows that everything is kinda executing at the same time because there is sleep(rand(1,3)) inside the OperatorThreaded class.

Any idea ?

Kaloyan Nikolov
  • 91
  • 1
  • 1
  • 10

1 Answers1

2

A Laravelly way is to do it like so:

  • Create a RequestYourApi Job (php artisan make:job RequestYourApi or make a class yourself inside App\Jobs).
  • Dispatch any amount of jobs using RequestYourApi::dispatch([/* args */]) (the arguments will be passed to the constructor of this class, and the job will be put into the queue, see https://laravel.com/docs/9.x/queues)
  • Run multiple workers using for instance Supervisor (or Laravel Horizon): php artisan queue:work (use --help to see additional options)
  • Scale up/down your workers depending on how fast you need to process things.
Flame
  • 6,663
  • 3
  • 33
  • 53