Speeding Up Apache, configuring Virtual Hosts the right way


A while back, I thought creating virtual hosts on my Windows development machine was a pretty novel way to develop my PHP applications. So I looked for how to configure my Windows machine and soon enough I modified my hosts file in order to add my virtual hosts.

In making the edits, I did something like this:

Prior to this time, my web server had been relatively good (speed-wise) and I never really noticed the speed drop until I tried to benchmark one of my apps.

When I did, I found out that a page request that was meant to be served in 100-200ms took between 5 and 7 seconds. At first, I thought maybe it was bottlenecks in my code but when I deployed the same application on the production server, response time dropped to the expected 100-200ms band.

So I fired up my browser and tried to Google a solution. I found this somehow related question on server fault: http://serverfault.com/questions/384136/apache-slow-at-responding

As indicated in the thread, the OP found his answer here: http://stackoverflow.com/questions/7547316/apache-virtualhost-slow-lookup/7553256#7553256

As it turns out, I put all of my Virtual Hosts definitions on the same line and it seemed to reduce the response time by about 65%. While this isn’t as fast as it once was, it’s definitely faster than 5-7 seconds.

Reference Links