drewlabs/async-http 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

drewlabs/async-http

最新稳定版本:v0.1.2

Composer 安装命令:

composer require drewlabs/async-http

包简介

Provides utility function(s) for making asynchronous HTTP requests

README 文档

README

The library provides an Async HTTP client for making HTTP request. It uses PHP streams API for send request to resource servers, there must only be used in environment that support PHP streams and sockets APIs.

Usage

To send HTTP request using this library, follow the examples below:

use function Drewlabs\Async\Future\await;
use function Drewlabs\Async\Http\createRequest;
use function Drewlabs\Async\Http\fetch;

// Creates the fetch client
$promise = fetch(createRequest('http://www.dneonline.com/calculator.asmx?wsdl', 'GET', null, []), ['debug' => true]); // Debugging should not be used in production

$response = await($promise);
printf("Content-Length: %d\n\r", strlen($response->getBody()));

If one is familiar which async syntax, one might do the following:

use function Drewlabs\Async\Http\createRequest;
use function Drewlabs\Async\Http\fetch;

// Creates the fetch client
$promise = fetch(createRequest('http://www.dneonline.com/calculator.asmx?wsdl', 'GET', null, []), ['debug' => true]); // Debugging should not be used in production

// Provide then handlers
$promise->then(function($response) {
	printf($response->getBody());
	printf($response->getStatusCode());
});

// wait for request to complete response
$promise->wait();

API

  • createRequest createRequest(string $url, string $method = 'GET', ?string $body = '', $headers = []) This function is used to create a request instance compatible with the fetch interface

  • createResponse createResponse(string $body = '', int $statusCode = 200, array $headers = [], string $reasonPhrase = 'OK') Creates a response instance compatible with one returned by the fetch interface

  • fetch fetch(RequestInterface $request): ResponseInterface fetch(RequestInterface[] $requests): ResponseInterface[] fetch(string $url): ResponseInterface HTTP client for sending HTTP request asynchronously.

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-09-25