Skip to content

Instantly share code, notes, and snippets.

@farconada
Last active October 28, 2015 08:13
Show Gist options
  • Save farconada/d59445416bafd6a73b27 to your computer and use it in GitHub Desktop.
Save farconada/d59445416bafd6a73b27 to your computer and use it in GitHub Desktop.
Async HTTP integration with PHP
As a way to integrate microservices I want to use HTTP calls and avoid the use of a MQ (Message Queue).
If the app is small and contained in one host you could avoid the use of MQ.
Description of the scenario:
I have one app (made with Symfony. Call it MainApp) and one microservice (made with Sylex. Call MicroApp), both served using PHP-FPM NGINX
1) MainApp calls an URL POST /api/internal/do-something with Guzzle,
2) then MicroAPP do its work (it takes long)
3) MicroApp calls an URL from /api/internal/i-have-finished
To avoid keep MainApp waiting in 1). I've configured a very small guzzle timeout and it catches the exception. With this trick I have an Async HTTP call.
Are there any way to 2) in background without a MQ (and without anykind of worker proccess).
I'm tempted to use threads for 2) but I've read that they are only suitable for CLI (https://github.com/krakjoe/pthreads).
I've heard that Spring have async REST.
What's the best way to solve this scenario and avoid waiting for 2) ?
@farconada
Copy link
Author

Dont you think that it will be a better solution with with threads? (pthreads are only available in CLI)

@farconada
Copy link
Author

Silex after() isn't the solution but $app->finish() do the work pretty well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment