承接 ginsen/http-client 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ginsen/http-client

最新稳定版本:v1.0.2

Composer 安装命令:

composer require ginsen/http-client

包简介

Http client handler with multiple asynchronous requests in parallel

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-23