webkul
webkul

Reputation: 2864

Using keep-alive feature in .htaccess

I want to use the keep-alive feature in Apache. How can I do this with my host (.htaccess file), and what are the best values for the parameters like KeepAliveTimeout?

Upvotes: 28

Views: 76471

Answers (7)

Baba
Baba

Reputation: 21

Paste the following code in your .htaccess file:

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

Then use this website: https://varvy.com/pagespeed/ to check if it's enabled.

Upvotes: 2

William Dresker
William Dresker

Reputation: 139

If you have SSH access to your server you should edit the Apache config file. Use these settings as a starter:

  • KeepAlive: on
  • KeepAliveTimeout: 3 seconds
  • MaxKeepAliveRequests: 60

This should work for most basic server setups with average traffic. You can always tweak the settings to suit your own needs. See here for more detailed info about this: http://www.giftofspeed.com/enable-keep-alive/

If you don't have access to your server you should contact your host. Changing the keepalive settings on your own by editing the .htaccess file will probably don't work.

Upvotes: 4

anil kumar
anil kumar

Reputation: 151

Yes Keep-alive behavior can be controlled in .htaccess file. First check the server setting by printing $_SERVER and if

[HTTP_CONNECTION] => keep-alive

is there then you just have to include the setting in your .htaccess file. Add the following line at the end of .htaccess file in your project's root directory.

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

Upvotes: 14

pronskiy
pronskiy

Reputation: 1358

If Keep-alive is turned on in the Apache configuration, all you need is just set an HTTP header Connection: keep-alive. E.g. add following lines to your .htaccess file:

<ifModule mod_headers.c>
    Header set Connection keep-alive
</ifModule>

Upvotes: 93

user177800
user177800

Reputation:

you can't control keep-alive behavior in .htaccess

Upvotes: 3

bobince
bobince

Reputation: 536567

You can't control keepalive behaviour in an .htaccess. Keepalives are a host-level feature, not one where different directories can behave differently depending on the per-directory htaccess info.

If you are on the kind of basic shared hosting that only gives you .htaccess to configure your sites, you can't change the keepalive settings. Presumably the hosting company will have set them appropriately, or just left them on the default settings, which are usually fine.

Upvotes: 18

tambler
tambler

Reputation: 3039

It very much depends on your site and the amount of traffic it receives. If a user comes to your site, then clicks through to another page within the KeepAliveTimeout setting (default is 15), a new TCP does not have to be created. This can really help with overhead.

On the other hand, any Apache processes that are currently tied up w/ existing visitors will not be able to talk to the new ones. So you may have to increase the total number of Apache processes that are available.

In short... it requires tweaking.

Upvotes: 3

Related Questions