Back to Top

How to Configure KeepAlive Directive in Apache

keepalive directive in apache

The keepalive directive in Apache is used to keeps the HTTP connection open instead of opening a new connection with each and every new request. This is also known as persistence connection which is the feature of HTTP/1.1 for long-lived HTTP connection.Here you will get the exact idea how to configure keepalive directive in apache.

Let’s see the syntax of KeepAlive directive:


KeepAlive On|Off

KeepAlive specifies whether persistent connections should be On or Off. Default value for KeepAlive is On so it is enabled by default and make connections keep open.You can disable persistent connection setting as Off.

Note: A KeepAlive connection with HTTP/1.0 can only be used if length of the content is known in advance.

Basically, KeepAlive directive keeps each HTTP connection open to avoid unnecessary delay. This is useful when client tries to make a several connection to the web server so the KeepAlive Directive allows client to make the different connection for every request. When you have lots of traffic on your website, this feature will create a problem in some cases because web server will have lots of unused open connection.

To Solve this issue when you have more traffic.You can set the KeepAliveTimeout to cache HTTP connection and to avoid waiting too long for the next request.

Let’s understand about the KeepAliveTimeout.


KeepAliveTimeout seconds

KeepAliveTimeout directive sets the number of seconds to wait for the next request and once the request has been received, the TimeOut directive applies.

TimeOut directive in Apache

Here is the syntax for TimeOut directive.


TimeOut seconds

Default seconds for TimeOut is 1200.You can set the maximum time so that the server will wait for the receipt of a request. TimeOut directive useful to downloads of large files over slow connections.

Here is the line of code you can set for KeepAlive and KeepAliveTimeout directive.

# Enable the KeepAlive Connection
KeepAlive On
# For specific 5 secs
KeepAliveTimeout 5

As per above code, the web server will cache that HTTP connection for the specific time which is here 5 seconds and it will not open unused and unrequired connections.

To Limit the number of connections

MaxKeepAliveRequests directive is used for a maximum number of KeepAlive requests per connection and it will have 0 for infinite.Let’s set the number of requests to perform a Persistent Connection.


MaxKeepAliveRequests number

Let’s see the example of MaxKeepAliveRequests directive:

MaxKeepAliveRequests 500

If this value is set to 0 then it will be considered as infinite requests.

Note: I recommend to set the higher value of this Directive for maximum server performance.

That’s it with KeepAlive directive.It is good to enable the KeepAlive Directive with KeepAliveTimeout.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts

What is Final keyword in PHP

Posted on 7 years ago


Learn about the Docker and how it works

Posted on 3 years ago


Getting started with Amazon Web Services

Posted on 3 years ago


Hello world

Updated 1 month ago

Nick Carter

In depth Understanding of Laravel Core

Updated 3 months ago


ECMAScript 6 New Features – 2

Updated 1 year ago


The Reader’s Poll – June 2015

Posted on 4 years ago


The Reader’s Poll – August 2014

Posted on 5 years ago


The Reader’s Poll – June 2014

Posted on 5 years ago


The Readers’ Poll – May 2014

Posted on 5 years ago


The Readers’ Poll – August 2013

Posted on 6 years ago