What is the difference between:
Header set Connection keep-alive
and
KeepAlive on
in Apache htaccess?
What code and options we have to put in the header of a php file? And what in htaccess file?
A keepalive (KA) is a message sent by one device to another to check that the link between the two is operating, or to prevent the link from being broken.
The Benefits of Connection Keep Alive The HTTP keep-alive header maintains a connection between a client and your server, reducing the time needed to serve files. A persistent connection also reduces the number of TCP and SSL/TLS connection requests, leading to a drop in round trip time (RTT).
Keep-Alive is an HTTP header that allows for the connection between a browser and a server to stay open, allowing the transfer of multiple files over a single connection. Without the HTTP Keep-Alive header, a new TCP connection would need to be opened for each file that needed to be retrieved to generate a page.
To enable Keep-Alive, you need to explicitly request it via the HTTP header by accessing . htaccess or the main configuration file of your web server. If you turn on Keep-Alive, the HTTP response header will show Connection: keep-alive.
If you simply set the header Connection: keep-alive
it isn't going to be enough. The client will think it's a keep-alive connection but the server may decide to close the connection. Additionally, the client doesn't know how many requests can be served through the keep-alive connection. There's an additional header that is used to track requests sent through a keep-alive connection that looks like this:
Keep-Alive: timeout=15, max=100
which tells the client that it can send up to 100 more requests on the current keep-alive connection (and it counts down as you continue to use said keep-alive connection) and that the client has 15 seconds to make any additioanl requests before the connection is closed.
Simply using the header isn't sufficient to establish a keep alive connection because the server needs to negotiate it. Both ends need to know about the keep-alive and both ends need to do proper accounting. You need to tell apache to handle keep-alive on its end and simply sending the header isn't going to do that. You need to turn keep-alive on using the second directive:
KeepAlive on
And additionally, you can tweak the keep-alive mechanism with directives like:
KeepAliveTimeout 15
MaxKeepAliveRequests 100
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With