In What conditions are closing a HTTP connection necessary?(在什么情况下需要关闭 HTTP 连接?)
问题描述
在什么情况下需要关闭 HTTP 连接?
In What conditions are closing a HTTP connection necessary?
推荐答案
HTTP 不是具有连接"的协议类型;这就是他们所说的无状态",这意味着每个请求都与其他请求分开.这就是为什么我们有会话cookie之类的东西;人们必须以某种方式进行黑客攻击,以允许信息在请求之间传递.
HTTP isn't the type of protocol to have "connections"; it's what they call "stateless", meaning each request is separate from every other request. That's why we have things like session cookies; people had to hack in a way to allow information to be carried over between requests.
现在,即使它们是分开的,HTTP 1.1 也允许客户端通过同一个 TCP/IP 连接发出多个请求(虽然它是到 HTTP 服务器的连接,但在 TCP/IP 栈).这些请求仍然是分开的,但您不必打开新的网络连接.这可以提高一些效率,因为打开网络连接可能会很昂贵.
Now, even though they're separate, HTTP 1.1 allows a client to make multiple requests over the same TCP/IP connection (which, although it's a connection to an HTTP server, is at a whole other level in the TCP/IP stack). The requests will still be separate, but you don't have to open a new network connection. This allows some efficiency gains, as opening a network connection can be expensive.
如果您想利用这一点,请查看请求和响应中的标头.如果请求使用的 HTTP 版本低于 1.1,或者标头显示 Connection: close
,则在处理完当前请求后,连接就会消失.否则,一旦它被清除(通常通过读取上一个请求中的所有数据),它就可以被重用.
If you'd like to take advantage of this, watch the headers in the request and response. If the request is using an HTTP version less than 1.1, or there's a header that says Connection: close
, then the connection is to go away after the current request is handled. Otherwise, once it's been cleared out (usually by reading all the data from the previous request), it can be reused.
这篇关于在什么情况下需要关闭 HTTP 连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在什么情况下需要关闭 HTTP 连接?


基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01