小编Fid*_*ity的帖子

使用PHP发出HTTP/2请求

有没有办法强制PHP与另一台服务器建立HTTP2连接只是为了查看该服务器是否支持它?

我试过了:

$options = stream_context_create(array(
               'http' => array(
                    'method' => 'GET',
                    'timeout' => 5,
                    'protocol_version' => 1.1
                )
              ));
$res = file_get_contents($url, false, $options);
var_dump($http_response_header);
Run Code Online (Sandbox Code Playgroud)

并试过:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTP_VERSION, 3);
$response = curl_exec($ch);
var_dump($response);
curl_close($ch);
Run Code Online (Sandbox Code Playgroud)

但是如果我使用以下URL,两种方式都会给我一个HTTP1.1响应 https://www.google.com/#q=apache+2.5+http%2F2

我正在从启用HTTP/2 + SSL的域发送请求.我究竟做错了什么?

php curl http2

4
推荐指数
1
解决办法
7048
查看次数

标签 统计

curl ×1

http2 ×1

php ×1