Handling multiple outbound API calls in a PHP web application

902 Views Asked by At

I'm working on a PHP (Zend Framework) web application that, for each user request, makes multiple calls to external APIs (SOAP and/or REST over HTTP).

At the moment, the API calls are sequential:

  • Call API A, wait around 1 second for results
  • Call API B, wait around 1 second for results
  • Send page back to the user

In this instance there is no dependency or relation between APIs A and B; I simply want to return the page with all the information as quickly as possible.

At the moment I'm thinking of either:

curl_multi_exec() would bind my client code for APIs A and B more tightly than I'd like.

ZeroMQ seems more complex to implement, and I'm not sure how I'd manage the worker processes and sockets.

Has anyone successfully implemented this behaviour in a PHP/Apache application without too much fuss?

1

There are 1 best solutions below

1
On

Sounds like you need a cache. They are pretty easy to make and can be either filesystem or any database extension.