PHP:获取HTTP协议版本(HTTP / 1.1与HTTP / 2) [英] PHP: Get HTTP Protocol Version (HTTP/1.1 vs HTTP/2)

查看:1161
本文介绍了PHP:获取HTTP协议版本(HTTP / 1.1与HTTP / 2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我的php应用程序假定HTTP 1.1无处不在。所以我定义了所有标题:

Until now my php application assumed HTTP 1.1 everywhere. So I defined all headers like so:

header("HTTP/1.1 500 Internal Server Error"); 

但现在我的服务器也支持HTTP 2,我想用正确的HTTP状态更新所有标头响应代码。

But now my server also supports HTTP 2 and I want to update all header responses with the right HTTP status code.

如何获取http请求的HTTP协议版本?

How to I get the HTTP Protocol version of the http request?

(我的网络服务器是nginx,但我想如果我使用的是nginx或apache则无关紧要。)

(My webserver is nginx, but I guess it is irrelevant if I am using nginx or apache.)

推荐答案

服务器协议应该可以从服务器环境通过 SERVER_PROTOCOL 获得,通常通过 $ _ SERVER ['公开您的应用程序中的SERVER_PROTOCOL']

The server protocol should be available through SERVER_PROTOCOL from the server environment, usually exposed through $_SERVER['SERVER_PROTOCOL'] inside your application.

来自Apache 2.4下的 phpinfo()

From phpinfo() under Apache 2.4:

SERVER_PROTOCOL => HTTP/1.1

这篇关于PHP:获取HTTP协议版本(HTTP / 1.1与HTTP / 2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆