Concurrency for Solo request #310
-
Is it possible to make concurrent requests with Solo Request? https://docs.saloon.dev/digging-deeper/concurrency-and-pools |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I believe it should be. At least in theory. Nonetheless, from a SoloRequest perspective, I think it should be quite easy. Maybe something like the following (but untested): $pool = new Pool(
// Same connector that individual SoloRequests use.
// So let's re-use a new one for all SoloReuqests, to utilise the same HTTP client.
connector: new NullConnector,
// Either iterable or a callable that returns an iterable of SoloRequests.
requests: function (): iterable {},
// Default is 5 concurrent Requests.
concurrency: 5,
// Handle Responses for the SoloRequests, or replace the callable with null, if none is needed.
responseHandler: function (Response $response, int|string $key, PromiseInterface $poolAggregate) {},
// Handle Exceptions for the SoloRequests, or replace the callable with null, if none is needed.
exceptionHandler: function (mixed $reason, int|string $key, PromiseInterface $poolAggregate) {},
);
// Then the regular flow applies.
$pool->send()->wait(); |
Beta Was this translation helpful? Give feedback.
I believe it should be. At least in theory.
However, for true concurrency, you'd need to use the same HTTP client, to my knowledge.
At least from a cURL perspective (Guzzle default).
But I could be wrong here.
Nonetheless, from a SoloRequest perspective, I think it should be quite easy.
But you could try to instantiate your own Pool, providing a Connector for all SoloRequests to run with (to use the same HTTP client).
See the Pool class for constructor arguments.
Maybe something like the following (but untested):