bart

Handle async Guzzle requests

Posted 1 year ago by bart

Hey everybody,

I'm currently working on a project where I would like to initiate an AJAX request to my backend which should call multiple APIs in parallel and should also return each result separately back to the frontend which should then process it.

I know that PHP isn't well known for multithreading so my main question is if it's possible and if yes, how would you tackle it?

I used the requestAsync() method of Guzzle which could be used to fire off multiple API requests in parallel. The problem is, that I need to wait for all responses before sending the response for the frontend. Do you have an idea if there is another way?

Alternatives I thought about could be:

  1. Fire multiple AJAX requests to my backend and pass something like an API parameter, so that the backend knows which API it should call for each request
  2. Queues could be another option to fire off multiple requests but I think I need to use pusher or something in that case to push the results of each API request into the frontend

What do you think about it?

Thanks a lot!!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.