Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Guzzle vs ReactPHP vs Amphp for parallel requests

What's the difference between:

  • GuzzleHttp
  • ReactPHP
  • Amphp

How they differ and what would be typical use case to use with?

like image 298
lubosdz Avatar asked Jan 30 '18 20:01

lubosdz


2 Answers

The main difference between those is that Guzzle is an HTTP client, while Amp and ReactPHP are generic async / event loop libraries. Both of these offer HTTP clients based on the core event loop they offer. Those are amphp/artax and reactphp/http-client.

Now, the difference between those and Guzzle is that those can do other things concurrently that are not HTTP requests. That is, because the user has full control over the event loop and can register own I/O watchers and timers, while the event loop that Guzzle uses is hidden from the user inside Curl.

If you just want to make a few concurrent HTTP requests, the decision mainly boils down to the API you like and a performance consideration maybe. If you want to do other I/O related things concurrently, use Amp or ReactPHP. If you want to stream your bodies, I'd suggest against using Guzzle, too.

like image 59
kelunik Avatar answered Nov 02 '22 14:11

kelunik


Hey ReactPHP core team member here. Both ReactPHP and Amp assume you're building an app with an event loop. If you just want to do a bunch of async requests and then continue, I would suggest using Guzzle's async requests: http://docs.guzzlephp.org/en/stable/quickstart.html#async-requests

If how ever you want to dive deeper into async request I suggest https://github.com/clue/php-buzz-react which gives you more control over the process plus it supports PSR-7.

like image 21
WyriHaximus Avatar answered Nov 02 '22 14:11

WyriHaximus