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:
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # 188.8.131.52 rhino.acme.com # source server # 184.108.40.206 x.acme.com # x client host # localhost name resolution is handled within DNS itself. # 127.0.0.1 localhost # ::1 localhost 127.0.0.1 localhost 127.0.0.1 com.testapp.local 127.0.0.1 local.example.com 127.0.0.1 local.google.com
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.