joopschilder / php-http2
v1.0.0
2019-12-07 16:59 UTC
Requires
- ext-curl: *
This package is not auto-updated.
Last update: 2024-10-01 21:11:09 UTC
README
安装
使用composer安装
$ composer require joopschilder/php-http2
这是什么?
这是一个使用HTTP/2
通过单个TCP连接发送请求的PHP的curl包装器。
提供以下内容
- 主要类
JoopSchilder\Http2\Http2
- 支持
curl
选项的简单请求类 - 简单的响应类
这不是什么?
一个现成的库。
我的意思是,当然,如果你认为它有用,你可以使用它。
示例
在bin/app.php
中有些示例代码。
在最基本的形式中,使用这个库可能看起来像这样
use JoopSchilder\Http2\Http2;
use JoopSchilder\Http2\Response;
$http2 = new Http2();
// Might also be an implementation of the ResponseHandler interface
$http2->onResponse(function(Response $response) {
var_dump($response);
});
// This creates a request with sensible defaults
$request = $http2->createRequest('https://www.twitter.com/');
$request->setOptions([CURLOPT_USERAGENT => 'AppleTV6,2/11.1']);
$http2->addRequest($request);
// Requests are not executed until this method is called
$http2->execute();
为每个你打算发送请求的主机使用不同的Http2
实例是个好主意。
接下来是什么?
- 为动态添加请求到
Http2
实例添加更多控制 - 创建一个与域名关联的
Http2
实例(这是它的预期用途) - 使用
PSR-7
HTTP消息接口 - 添加请求的工厂