apache tutorial - How to use keep-alive connections to improve performance - apache - apache web server - apache server - apache2
Using keep-alive connections
- Keep-alive connections use a single TCP connection to handle multiple HTTP requests and responses.
- Instead of opening a new TCP connection every time a brower sends a request, keep-alive connections enable clients and servers to communicate more efficiently and use fewer resources.
- Many performance testing sites, such as GTMetrix, check if keep-alive connections are enabled for a site.
- If they are disabled, you receive a lower site performance score.
- If keep-alive conections are disabled for your site, you can easily enable them. To do this, follow these steps:
- Edit or create an .htaccess file in your site's document root directory.
- Copy the following lines and paste them into the .htaccess file:
- Save your changes to the .htaccess file. Keep-alive connections are now enabled.
- To verify that keep-alive connections are enabled, you can examine the raw HTTP headers sent between the browser and web server.
- To do this, use a browser plugin that displays the raw headers such as Live HTTP headers for Mozilla Firefox, or the Developer Tools feature in Google Chrome.
- When keep-alive connections are enabled, Apache adds the following line to the HTTP response header: