Guzzle vs ReactPHP vs Amphp for parallel requests
Asked Answered
P

2

10

What's the difference between:

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

Perseid answered 30/1, 2018 at 20:54 Comment(2)
Multi-curl (or multi-curl wrapped in Guzzle) is your best bet. This uses C threads to parallelise requests, and returns control when the last one has finished.Acquirement
This question doesn't ask for a book, tool, or library. The author asked for the difference between those, which is a totally valid question. Some use cases might be opinion-based, but the current close reason is definitely wrong.Tantalum
T
16

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.

Tantalum answered 5/2, 2018 at 8:21 Comment(1)
"those can do other things concurrently that are not HTTP requests" Not entirely true. Guzzle uses Promises in github.com/guzzle/promises which can be used for "other things".Korman
W
5

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.

Wadsworth answered 30/1, 2018 at 21:21 Comment(3)
This answer is incomplete. Amp offers Amp\Promise\wait() specifically for applications that are not entirely asynchronous. ReactPHP offers similar functions in the external clue/php-block-react package. The major difference between those and Guzzle is that Amp and ReactPHP additionally allow other non-blocking I/O and timers, not only concurrent HTTP requests.Tantalum
Guzzle does support PSR-7, cancelling promises and $promise->wait() synchronnous handler - github.com/guzzle/promises.Perseid
I am building a framework and I want to build it on top of an Async base, Can ReactPHP provide the same functionality and power as Swoole? I love Swoole but its so badly documented, its hard to even trust its secureLotetgaronne

© 2022 - 2024 — McMap. All rights reserved.