Browsing to localhost is slow when connected to Internet

4

When I browse localhost in my browser when connected to the Internet, the response is slow; it takes 30 seconds or completely times out. When I disconnect from the Internet, it is blazing fast and loads instantly.

What is going on? This is very annoying. I'm using Windows 7 Home Premium with Apache installed.

No changes have been made to the system.

Codebeat

Posted 2013-05-14T02:27:13.907

Reputation: 312

How about your network setting ? – matzone – 2013-05-14T08:08:49.423

@matzone: What network setting? – Codebeat – 2013-05-14T13:57:57.727

Your TCP/IP setting .. I don't know much about this, but mostly occured in DHCP setting .. – matzone – 2013-05-14T16:30:59.243

Answers

2

Al right, it seems no problem of the system itself, windows or network but remove some hidden networkcard configurations from the past and disable all WAN-miniports in the hardware configuration that increases the speed a little.

But that was not the problem causing the long delays when connected to the internet. In the php code there was some cURL code that connects to a slow site to get some additional useragent info (REST interface). Because the data was not cached and the site access slow down in time for some reason, it connects to this slow site for each part of the webpage. This caused the long delays.

Now it is cached, the problem no longer exists. Thanks for the input anyway.

Codebeat

Posted 2013-05-14T02:27:13.907

Reputation: 312

4

What's probably going on when you are connected to Internet is that your system tries to resolve name localhost in yours ISP DNS servers.

As a solution you can define name localhost as IP address 127.0.0.1 in your hosts file which is read before querying DNS servers. Since you have Windows 7 you should have required entry in C:\Windows\System32\drivers\etc\hosts file but by default it's commented out. Start Notepad as Administrator by right-clicking on it and choosing Run as Administrator. Open your hosts file and change lines:

#   127.0.0.1       localhost
#   ::1             localhost

to:

127.0.0.1       localhost
::1             localhost

Basically uncomment it by removing # from the beginning of these two lines. Save the file and test if it resolved your problem.

esz

Posted 2013-05-14T02:27:13.907

Reputation: 41

I appreciate your answer, but already tried that without success! One said that to remove it and the other said to add it. It makes really no sense to the problem. – Codebeat – 2013-05-14T13:56:26.877

0

You have to make sure that all entries for 127.0.0.1 are placed on the same line in the hosts file. A configuration like this:

127.0.0.1 localhost
127.0.0.1 mysite

should be changed to:

127.0.0.1 localhost mysite

This small modification has increased the speed at my Windows based system incredibly.

W.M.

Posted 2013-05-14T02:27:13.907

Reputation: 111

Can you provide some evidence for the "speed increase"?. That change will only have a tiny effect on DNS lookups. – DavidPostill – 2016-04-12T13:04:58.850

I know in Linux this should not have any impact, but at my Windows setup I have struggled with this issue for months until I did the modification mentioned above. The change is dramatic. It was taking several seconds to load the page (especially first visit to site), now the pages get loaded instantaneously (no delays at all). – W.M. – 2016-04-12T13:54:35.053

1I have struggled a lot especially with Docker believing it was slow to read disk files. For months I thought 7,000ms was -okay- when using Docker on Windows. This resolved the issue. – Shafiq al-Shaar – 2019-07-28T00:17:34.057