Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I enable keep-alive?

I ran a Google Page Speed and it says I scored 57/100 because I need to "Enable Keep-Alive" and "Enable Compression". I did some Google searches but I can't find anything. I even contacted my domain provider and asked them to turn it on, but they said it was already on.

Long story short:

1.) What is Keep-Alive?

2.) How do I enable it?

like image 822
John Doe Avatar asked Nov 22 '11 18:11

John Doe


2 Answers

Configure Apache KeepAlive settings

Open up apache’s configuration file and look for the following settings. On Centos this file is called httpd.conf and is located in /etc/httpd/conf. The following settings are noteworthy:

  • KeepAlive: Switches KeepAlive on or off. Put in “KeepAlive on” to turn it on and “KeepAlive off” to turn it off.

  • MaxKeepAliveRequests: The maximum number of requests a single persistent connection will service. A number between 50 and 75 would be plenty.

  • KeepAliveTimeout: How long should the server wait for new requests from connected clients. The default is 15 seconds which is way too high. Set it to between 1 and 5 seconds to avoid having processes wasting RAM while waiting for requests.

Read more about benefits of keep alive connection here: http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

like image 105
Tamik Soziev Avatar answered Sep 23 '22 08:09

Tamik Soziev


Keep-alive is using the same tcp connection for HTTP conversation instead of opening new one with each new request. You basically need to set HTTP header in your HTTP response

Connection: Keep-Alive 

Read more here

like image 25
pavel_kazlou Avatar answered Sep 23 '22 08:09

pavel_kazlou