Keep-Alive - Apache And Headers By .htaccess And PHP

Posted at

Set your keep-alive connection, configure your Apache "on-the-fly" and send the proper headers, all using .htaccess. Simple.

# Option #1: .htaccess
<ifModule mod_env.c>
SetEnv KeepAlive On
SetEnv KeepAliveTimeout 100
SetEnv MaxKeepAliveRequests 500

#set external-responses data
<ifModule mod_headers.c>
Header unset Connection
Header set Connection keep-alive

Header unset Keep-Alive
Header set Keep-Alive timeout=99,max=499

Even more dynamic than a folder-based configuration is a PHP file based-one (and the headers too...)
  /* Option #2: PHP */

  /* setting Apache */
  apache_setenv("KeepAlive", "On");
  apache_setenv("KeepAliveTimeout", "100");
  apache_setenv("MaxKeepAliveRequests", "500");
  /* setting headers */
  header("Connection: keep-alive");
  header("Keep-Alive: timeout=99, max=499");