Since setting up my development environments on Mac OS X Lion (brand new macbook air purchased in January 2012), I have noticed that resolving to a virtual host is very slow
A dumb issue that led me to waste some considerable time: after applying @Cleverlemming's answer, I figured out that there were duplicated entries on the hosts file. Something like:
::1 site1.local site2.local site1.local site3.local site4.local
fe80::1%lo0 site1.local site2.local site1.local site3.local site4.local
127.0.0.1 site1.local site2.local site1.local site3.local site4.local
Then IP resolving for site3.local and site4.local takes these 5-seconds of death.
On OSX El Capitan what worked for me was making a duplicate IPv6 entry right above the IPv4 entry like so
fe80::1%lo0 demo.test.dev
127.0.0.1 demo.test.dev
The trick that did it for me was adding
127.0.0.1 locahost
on the first line of the host file.
From all my virtual hosts, only the ones using a database were slow. I believe it's because the process of looking up "localhost" for the database connection slowed things down, since I only added the addresses for my virtual hosts and not "localhost" as well. Now it's all snappy again. :)
I had the exact same problem and it was driving me crazy!
Put all your hosts file entries for localhost into one line like so:
127.0.0.1 localhost myproject.dev myotherproject.dev
::1 localhost
fe80::1%lo0 localhost
Worked like a charm for me. Seems like a bug in Lion.
Make sure to put the IP v6 entries not in the line with localhost
::1 localhost
the IP v6 entries go in a separate line
fe80::1%lo0 here and_here
It is sometimes really fast now, but there are rare exceptions where the old lags come back. They might however be based on other reasons.
Specifying same host for IPv6 ::1 helped me.
127.0.0.1 something.local.mydomain.org
::1 something.local.mydomain.org