X
X
X
X

Knowledge Base

HomepageKnowledge BaseAlojamientoHosting terminologyWhat is Keep-Alive?

What is Keep-Alive?

Keep-Alive (also called HTTP persistent connection or HTTP keep-alive) is a web server setting that allows you to set the type of connection between a web server and a web browser.

When a website is accessed, the web browser connects to the web server over the Internet using network protocols (TCP / IP). Each TCP network connection is a communication channel through which a web browser and a web server exchange HTTP requests and HTTP responses.

By default, a web page is a collection of many separate resources such as images (.jpg, .png…), style (.css), interactivity (.js…) documents (.doc, .pdf…), multimedia (.flv, .mp3 ) and other.

These objects are separate from the HTML code of the web page itself and do not even have to be on the same server. In reality, only pointers are placed in the HTML code through which these resources are called. After receiving the HTML code of the web page, the web browser reads the directories and sends to the web server one HTTP request for each resource.

When Keep-Alive is not used, a separate communication channel (TCP connection) will be created between the web server and the web browser for each individual HTTP request. After the web server provides an HTTP response to the HTTP request, the connection is terminated. At the next request from the web browser, the web server will open a new communication channel. To the loading time of the web page is added the time to create and terminate each TCP connection. When there are more objects, it significantly slows down the final loading of the web page.

When Keep-Alive is used, the communication channel (TCP connection) between the web browser and the web server is not terminated after only one HTTP request / response. Instead, the connection remains open and multiple HTTP requests / responses are transmitted over it. The connection is terminated when there are no more requests from the web browser.

With a persistent communication channel, the web browser can request multiple resources from the server and receive them on the same channel. This eliminates the extra time spent creating and disconnecting multiple connections to the web server, and loading web pages is significantly faster.

In version 1.1 of the HTTP protocol, Keep-Alive is described as the default method for the connection between a web server and a web browser.

Information about the connection method is given in the header of the HTTP request and the HTTP response.

Example HTTP request and HTTP response:

HTTP request from the web browser:

GET / HTTP/1.1
Host: vpsextra.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:35.0) Gecko/20100101 Firefox/35.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: bg,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive

HTTP response from the web server:

HTTP/1.1 200 OK
Date: Mon, 19 Jan 2015 12:14:41 GMT
Server: Apache
Connection: Keep-Alive
Keep-Alive: timeout=5, max=5
Content-Type: text/html; charset=UTF-8

Two parameters can be set in the Keep-Alive web server settings:

  • timeout – after how much time of inactivity on the communication channel, to terminate the connection; in seconds; if no new HTTP request is received on the channel, the connection is terminated;
  • max – maximum number of applications that can be submitted per communication channel.

Disconnection can be triggered either by the web browser or the web server by submitting Connection: close in the headers of the last request / response.

To check if Keep-Alive is enabled on the web server, look at the HTTP headers of its HTTP response.

You can view HTTP headers sent from the web server either through a web browser, using a developer tool, or through an online tool such as: https://www.dnsqueries.com/en/googlebot_simulator.php
(Enter the website address in the WebPage field)
Keep-Alive is enabled if the HTTP response contains Connection: Keep-Alive.

Can't find the information you are looking for?

Create a Support Ticket
Did you find it useful?
(770 times viewed / 543 people found it helpful)

Top