ginsen/http-client
最新稳定版本:v1.0.2
Composer 安装命令:
composer require ginsen/http-client
包简介
Http client handler with multiple asynchronous requests in parallel
README 文档
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()); }
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-23