Apache slow time to first byte TTFB linked to slow DNS lookup [localhost]

A really brief post here

I had an issue where I had a virtual domain (say jaspreetchahal.org) configured with apache virtual hosts and in my hosts file entries on my iMac (sudo vi /etc/hosts), I want this domain to resolve to

The problem I had was that sometimes it was taking up to 10 seconds for something to show up,  I checked pretty much all my configurations, I didn’t see any issue with those.

Then I diverted my attention to the hosts file itself just to found out that I had over 20 test domain records resolving to

What I did then resolved the issue for me

I consolidated all my domains to a single line as shown below

and removed all the unwanted records from the hosts file

Tada! that’s how fast it should be on a localhost. 🙂

This is what solved for me, I am not saying that it will for you too, there could be several other reasons associated with this issue. There are far too many things that could contribute to the slowness, if you solved it in any other way, feel free to share.

I hope this helps.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.