Enable keep-alive in Apache

What is keep alive?


Keep alive is a method to allow the same tcp connection for HTTP conversation instead of opening a new one with each new request. More simply put, it is a communication between the web server and the web browser that says “you can grab more than just one file at a time”. Keep alive is also known as a persistant connection.

– Source

Advantages of KeepAlive

  • Improves website speed: It reduces latency associated with HTTP transfers and delivers a better user experience.
  • Reduces CPU usage: On the server side enabling KeepAlive reduces CPU usage. Consider that a typical web page has dozens of different files such as images, stylesheets, javascript files etc. If KeepAlive is disabled a separate connection must be made for each of those files. Creating and closing connections has an overhead and doing it for every single file wastes CPU time.

Disadvantages of Keepalive

  • Increases memory usage: Enabling KeepAlive  increases memory usage on the server. Apache processes have to keep connections open waiting for new requests from established connections. While they are waiting they are occupying RAM that could be used to service other clients. If you turn off KeepAlive fewer apache processes will remain active. This will lower memory usage and allow Apache to serve more users.


Edit httpd.conf.

vi /etc/httpd/conf/httpd.conf

Edit the following section – KeepAlive On.

# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
KeepAlive On

# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
MaxKeepAliveRequests 100

# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
KeepAliveTimeout 100

Restart httpd.

/etc/init.d/httpd restart

Browser Caching via .htaccess

I added simple browser caching through my .htaccess file.

vi .htaccess

IMPORTANT: Add the following to the top of the file.

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 1 month"

Enable mod_deflate On CentOS 6 (Enable Compression)

Add to .htaccess.

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE text/css
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE image/x-icon
  AddOutputFilterByType DEFLATE image/svg+xml
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE application/x-font
  AddOutputFilterByType DEFLATE application/x-font-truetype
  AddOutputFilterByType DEFLATE application/x-font-ttf
  AddOutputFilterByType DEFLATE application/x-font-otf
  AddOutputFilterByType DEFLATE application/x-font-opentype
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  AddOutputFilterByType DEFLATE font/ttf
  AddOutputFilterByType DEFLATE font/otf
  AddOutputFilterByType DEFLATE font/opentype

# For Olders Browsers Which Can't Handle Compression
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Backup Address Book on MAC

Most of us have joined the icloud extravaganza and are now dependent on Apple not losing our data. Just imagine how upset you would be if you all of a sudden lost all your contacts. I personally am running OSX Lion 10.7.2 and I’m going to show you a simple way to backup your Address Book contacts onto your local hard drive.

  • Launch Address Book
  • File > Export… > Archive Address Book…

  • Choose a saving destination (I choose my desktop for now)

You should now have an ABBU (Address Book BackUp) file called Address Book – <date> saved to your computer.

To recover you contacts:

  • Launch Address Book
  • File > Import…
  • Choose your backup file Address Book – <date>

iCloud Verification email

I ran into a problem when trying to setup my iCloud account with Apple. No matter what I did, I couldn’t figure out how to complete the verification email part of the setup, as Apple needed my Apple ID to be an email address (the one I was using was not). I tried a few things and had no luck figuring out the problem. Come to find out, it looks like I had multiple Apple IDs related to the same email account.

A very nice guy by the name of Rob Wheatley posted the fix in Apple’s discussions.

I first went to appleid.apple.com and clicked the Find out link at the bottom right of the page.

I was then shown two Apple ID’s that were associated to my email address.

  • r1tommy
  • r1tommy@gmail.com

I logged into my r1tommy@gmail.com Apple ID (the account that I never used) and changed it to r1tommy@hotmail.com (now r1tommy@gmail.com is only associated to my r1tommy Apple ID account).

I then logged into my r1tommy Apple ID (all my apps & music is purchased on this account). I was given the option to merge my r1tommy Apple ID & r1tommy@gmail.com together as one (like two peas in a pod), making my r1tommy@gmail.com my primary Apple ID.

Everything then fell into place and worked seamlessly.