简体   繁体   English

如何使用php覆盖Apache keep-alive标头?

[英]How to override Apache keep-alive header using php?

in my httpd.conf there is: 在我的httpd.conf中有:

KeepAliveTimeout 1

I'm trying to override Apache KeepAliveTimeout setting in a single php script (not in the entire server) so I have a php script with: 我试图在单个 php脚本中(而不是在整个服务器中)覆盖Apache KeepAliveTimeout设置,所以我有一个php脚本,其内容如下:

header("Keep-Alive: timeout=60, max=100"); 

but it doesn't seem to make any difference. 但这似乎没有任何区别。 still I get in the response: 我仍然得到回应:

Keep-Alive:timeout=1, max=50

any ideas how to solve this? 任何想法如何解决这个问题?

You can't do that. 你不能那样做。 It's there in place for a valid reason. 出于适当的原因,它就在那儿。

Apache v2.2 Core Features Apache v2.2核心功能

KeepAliveTimeout Directive KeepAliveTimeout指令

The number of seconds Apache will wait for a subsequent request before closing the connection. Apache在关闭连接之前等待后续请求的秒数。 Once a request has been received, the timeout value specified by the Timeout directive applies. 收到请求后,将应用Timeout指令指定的超时值。

Setting KeepAliveTimeout to a high value may cause performance problems in heavily loaded servers . KeepAliveTimeout设置为较高的值可能会导致负载较重的服务器出现性能问题。 The higher the timeout, the more server processes will be kept occupied waiting on connections with idle clients. 超时时间越高,等待与空闲客户端进行连接的服务器进程将被占用的时间越多。

Try setting it in the .htaccess file combined with a FilesMatch directive. 尝试将其与FilesMatch指令结合在.htaccess文件中进行设置。 See this post . 看到这篇文章

<?php
header('Connection: close');
// other php code here...
// ...

From RFC 2616, Section 14.10: 根据RFC 2616第14.10节:

HTTP/1.1 defines the "close" connection option for the sender to HTTP / 1.1为发件人定义了“关闭”连接选项
signal that the connection will be closed after completion of the 表示完成连接后将关闭连接
response. 响应。 For example, 例如,

  Connection: close 

in either the request or the response header fields indicates that the connection SHOULD NOT be considered `persistent' (section 8.1) 在请求或响应标头字段中,指示不应将连接视为“持久”(第8.1节)
after the current request/response is complete. 当前请求/响应完成后。

HTTP/1.1 applications that do not support persistent connections MUST include the "close" connection option in every message. 不支持持久连接的HTTP / 1.1应用程序必须在每条消息中都包括“关闭”连接选项。

Related: What does “Connection: close” mean when used in the response message? 相关: 在响应消息中使用“连接:关闭”是什么意思?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM