HTTP (Hyper Text Transfer Protocol) does not maintain a state. For every request that is made to the server, the server sends a response back. When a request is being made, a NEW socket connection is opened on the server from which the response is sent back.

The biggest disadvantage of http is its”slow” response. “Keep-alive” connections phase out this problem for HTTP.

Http keep-alive is also known as “persistent connections”.

In HTTP/1.0 specification, the browser sends the request with the header tag “Connection: Keep-Alive” to which the server responded back with “Connection: Keep-Alive”. For this to happen, it is essential that the browser should support keep-alive. When the next request is sent, the connection is NOT CLOSED and is still alive for further requests until either client or server decides that the connection is over and closes the connection.

In HTTP/1.1 specification, ALL connections to the server are treated to be having “keep-alive” connection unless explicitly stated with “Connection: close” in the headers from the browsers. Some browsers misbehave by hanging the connection. To over come this problem, there is a Keep Alive TimeOut option available in Servers and in Apache it defaults to 15 seconds.

Keep-alive is active with files whose size are known before hand. So dynamic programs stay aside on these cases.

HTTP indicates the end of the previous response and the beggining of the new request thus enabling the reuse of the connection.

Refer:

RFC 2616: http://tools.ietf.org/html/rfc2616#section-8.1