我已经有在亚马逊服务器中运行的YII(1.1.14)应用程序。所以我计划使用HTTP2,所以请告诉我任何人在我的应用程序中使用HTTP2的过程是什么。
尝试 h2o 和 curl。 H2O 从 v 1.3 开始支持 php-fpm。这是h2o.conf的例子。
file.custom-handler:
extension: .php
fastcgi.connect:
host: 127.0.0.1
port: 9000
type: tcp
listen:
port: 8080
ssl:
certificate-file: /path/to/server.crt
key-file: /path/to/server.key
hosts:
"127.0.0.1.xip.io:8080":
paths:
/:
file.dir: /path/to/public_html
您可以使用使用 nghttp2 构建的 libcurl 创建 http2 请求。您所要做的就是使用 CURL_HTTP_VERSION_2_0
.
if (!defined('CURL_HTTP_VERSION_2_0')) {
define('CURL_HTTP_VERSION_2_0', CURL_HTTP_VERSION_1_1 + 1);
}
$url = 'https://http2bin.org/get';
$opts = [
CURLOPT_VERBOSE => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
];
$ch = curl_init($url);
curl_setopt_array($ch, $opts);
curl_exec($ch);
curl_close($ch);
我还建议试一试 H20。到目前为止,它一直很稳定。如果您熟悉 YAML 或类似内容,则配置非常清晰易行。
这里有一篇文章让你开始使用Yii,HHVM和HTTP/2:https://www.symfony.fi/entry/serving-php-on-http-2-with-h2o-and-hhvm-symfony-wordpress-drupal