[php]fopen使用HTTP/1.1协议
php版本:5.6.40
注:在没有配置protocol_version的情况下,protocol_version默认值为1.0.
fopen使用1.1协议写法:
<?php
$stream = stream_context_create([
"http" => [
"protocol_version" => 1.1 //使用1.1协议
]
]);
$f = fopen("http://mydomain.com", "r", false, $stream);
fclose($f);
yii2 使用1.1协议写法:
$client = new \yii\httpclient\Client();
$client->transport = 'yii\httpclient\CurlTransport';
$response = $client->createRequest()
->setMethod('GET')
->setUrl('mydomain.com')
->setOptions([
"protocol_version" => 1.1 //使用1.1协议
])
->send();
php-src 5.6.40部分源码:
php-src/ext/standard/http_fopen_wrapper.c
/* protocol version we are speaking */
if (context && (tmpzval = php_stream_context_get_option(context, "http", "protocol_version")) != NULL) {
char *protocol_version;
spprintf(&protocol_version, 0, "%.1F", zval_get_double(tmpzval));
smart_str_appends(&req_buf, " HTTP/");
smart_str_appends(&req_buf, protocol_version);
smart_str_appends(&req_buf, "\r\n");
efree(protocol_version);
} else {
smart_str_appends(&req_buf, " HTTP/1.0\r\n");
}