i have a bunch of laravel jobs who connect to an external API, fetch some data and processes the data. Because it is very different data, i splitted it into multiple jobs (GET_DATA_A, GET_DATA_B, ...)
But every jobs creates a new HttpClient (Guzzle) and a new connection to the API, which makes the API very slow.
Is there a solution to use one HttpClient (with keep-alive) for all jobs?
Best regards
CodePudding user response:
This is possible to achieve because the queue worker is a long running process.
As long as your settings for the queue worker are not causing it to exit early (such as a low max job count, or low max time) it should be possible.
You need to use the singleton pattern to reuse the guzzle client. Then you can reuse the same client across your jobs.