5

in my httpd.conf there is:

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:

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?

David
  • 51
  • 1
  • 1
  • 3

3 Answers3

2

You can't do that. It's there in place for a valid reason.

Apache v2.2 Core Features

KeepAliveTimeout Directive

The number of seconds Apache will wait for a subsequent request before closing the connection. Once a request has been received, the timeout value specified by the Timeout directive applies.

Setting KeepAliveTimeout to a high value may cause performance problems in heavily loaded servers. The higher the timeout, the more server processes will be kept occupied waiting on connections with idle clients.

जलजनक
  • 3,072
  • 2
  • 24
  • 30
  • 1
    I don't see that documentation says that this is not possible. I know what keep-alive is, and I'm aware of the implications. That's exactly why I want to change KeepAliveTimeout for only one single php script, which is requested every few seconds. In the current state, the user creates new connections every few seconds. I would like it to reuse the first connection – David Mar 09 '13 at 08:46
  • Ability to control resides with Apache. Say if it's allowed then what's the point of keeping it? Then it ought to be called `DefaultKeepAliveTimeout`. If server is yours, why not increase at Apache? – जलजनक Mar 09 '13 at 08:57
  • 3
    As I said, increasing the value in httpd.conf will increase the value for **all** transactions. As you wrote before, there is performance hit when setting high value for all of the transactions. That's why I would like to do it for a specific php script. – David Mar 09 '13 at 12:19
0

Try setting it in the .htaccess file combined with a FilesMatch directive. See this post.

Community
  • 1
  • 1
user3629081
  • 101
  • 3
0
<?php
header('Connection: close');
// other php code here...
// ...

From RFC 2616, Section 14.10:

HTTP/1.1 defines the "close" connection option for the sender to
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)
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.

Related: What does “Connection: close” mean when used in the response message?

Community
  • 1
  • 1
Anthony Hatzopoulos
  • 10,437
  • 2
  • 40
  • 57