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 thefetchinterface -
createResponse
createResponse(string $body = '', int $statusCode = 200, array $headers = [], string $reasonPhrase = 'OK')Creates a response instance compatible with one returned by thefetchinterface -
fetch
fetch(RequestInterface $request): ResponseInterfacefetch(RequestInterface[] $requests): ResponseInterface[]fetch(string $url): ResponseInterfaceHTTP client for sending HTTP request asynchronously.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-25