简体   繁体   中英

How to override Apache keep-alive header using php?

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?

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.

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

<?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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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