开发者

Using keep-alive feature in .htaccess

I want to use the keep-ali开发者_开发技巧ve feature in Apache. How can I do this with my host (.htaccess file), and what are the best values for the parameters like KeepAliveTimeout?


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>


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.


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>


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.


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜