ginsen / http-client
Http client handler with multiple asynchronous requests in parallel
v1.0.2
2025-06-24 11:31 UTC
Requires
- php: ^8.0
- ext-curl: *
- guzzlehttp/guzzle: ^6.0 | ^7.0
- php-http/guzzle7-adapter: ^1.1
- psr/http-message: ^2.0
Requires (Dev)
- nyholm/psr7: ^1.8
- phpunit/phpunit: ^12.2
- symfony/var-dumper: ^7.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This library allows you to make several HTTP requests in parallel, reducing the overall time of the set of requests.
You can use it for a single request by following the PSR-18 HTTP Client, see the test snippet.
#[Test] public function it_should_handler_one_request_as_psr_18(): void { $client = new HttpClient(); $response = $client->sendRequest( new Request('GET', 'https://jsonplaceholder.typicode.com/todos/1') ); self::assertInstanceOf(ResponseInterface::class, $response); self::assertSame(200, $response->getStatusCode()); }
Or you can send a collection of Psr\Http\Message\RequestInterface and retrieve an array of
Psr\Http\Message\ResponseInterface, see the test.
#[Test] public function it_should_handler_several_requests(): void { $client = new HttpClient(); $requests['todos'] = new Request('GET', 'https://jsonplaceholder.typicode.com/todos/1'); $requests['posts'] = new Request('GET', 'https://jsonplaceholder.typicode.com/posts/1'); $responses = $client->sendRequest(...$requests); self::assertInstanceOf(ResponseInterface::class, $responses['todos']); self::assertInstanceOf(ResponseInterface::class, $responses['posts']); self::assertSame(200, $responses['todos']->getStatusCode()); self::assertSame(200, $responses['posts']->getStatusCode()); }