问题描述
有什么区别:
Header set Connection keep-alive
和
KeepAlive on
在 Apache htaccess 中?
in Apache htaccess?
我们必须在 php 文件的标题中放入哪些代码和选项?htaccess 文件中有什么?
What code and options we have to put in the header of a php file? And what in htaccess file?
推荐答案
如果只设置标题 Connection: keep-alive
是不够的.客户端会认为这是一个保持活动的连接,但服务器可能会决定关闭连接.此外,客户端不知道可以通过保持活动连接提供多少请求.还有一个额外的标头用于跟踪通过保持活动连接发送的请求,如下所示:
If you simply set the header Connection: keep-alive
it isn't going to be enough. The client will think it's a keep-alive connection but the server may decide to close the connection. Additionally, the client doesn't know how many requests can be served through the keep-alive connection. There's an additional header that is used to track requests sent through a keep-alive connection that looks like this:
Keep-Alive: timeout=15, max=100
它告诉客户端它可以在当前的保持连接上再发送 100 个请求(并且它在您继续使用所述保持连接时倒计时)并且客户端有 15 秒的时间进行任何添加在连接关闭之前请求.
which tells the client that it can send up to 100 more requests on the current keep-alive connection (and it counts down as you continue to use said keep-alive connection) and that the client has 15 seconds to make any additioanl requests before the connection is closed.
仅使用标头不足以建立保持活动连接,因为服务器需要协商它.两端都需要知道keep-alive,并且两端都需要做适当的记账.您需要告诉 apache 在其结束时处理 keep-alive 并且简单地发送标头不会这样做.您需要使用第二个指令打开保持活动状态:
Simply using the header isn't sufficient to establish a keep alive connection because the server needs to negotiate it. Both ends need to know about the keep-alive and both ends need to do proper accounting. You need to tell apache to handle keep-alive on its end and simply sending the header isn't going to do that. You need to turn keep-alive on using the second directive:
KeepAlive on
此外,您可以使用以下指令调整保持活动机制:
And additionally, you can tweak the keep-alive mechanism with directives like:
KeepAliveTimeout 15
MaxKeepAliveRequests 100
这篇关于Apache Htaccess中KeepAlive的正确使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!