very slow file_get_contents

eknip

Verified User
Joined
Jul 29, 2009
Messages
21
Hi all,

I'm having a problem with PHP's function file_get_contents. It only happens with hostnames, e.g. echo file_get_contents('http://www.google.com'); which takes up to 8 seconds before it's getting the file contents.

When I'm using file_get_contents() with an IP address it loads the page in less than a second.

So, it seems something is wrong with my DNS settings. However, when I login with SSH on the webserver I can ping www.google.com and traceroute www.google.com in less than a second aswell.

Does anybody have any suggestions to find out how to fix this problem?

Thanks!
 
What about commands like host or nslookup
 
host returns this:

www.google.com is an alias for www.l.google.com.
www.l.google.com has address 74.125.77.104
www.l.google.com has address 74.125.77.147
www.l.google.com has address 74.125.77.99
www.l.google.com has IPv6 address 2a00:1450:8001::67
www.l.google.com has IPv6 address 2a00:1450:8001::68
www.l.google.com has IPv6 address 2a00:1450:8001::69
www.l.google.com has IPv6 address 2a00:1450:8001::6a
www.l.google.com has IPv6 address 2a00:1450:8001::93
www.l.google.com has IPv6 address 2a00:1450:8001::63

nslookup returns this:

Server: 85.17.150.123
Address: 85.17.150.123#53

Non-authoritative answer:
www.google.com canonical name = www.l.google.com.
Name: www.l.google.com
Address: 74.125.77.147
Name: www.l.google.com
Address: 74.125.77.99
Name: www.l.google.com
Address: 74.125.77.104
 
Is it just as fast or is it slow? I dont know what would be any different on php. I guess you should start googling to what causes slow dns lookups with php. Maybe there are some settings you can tweak in php.ini
 
It's just as fast. The DNS seems to work fine in SSH, but not in PHP.The strange/interessting thing is that it's superfast when I'm using an IP address OR a domainname that is hosted on the server itself.

Hopefully someone has experienced simular problems and found a solution.
 
Ok, it seems I've found out why this happens. My server currently runs on IPv4, while sites like google.com run on IPv6. I recommend to anyone who's experiencing simular problems to enable IPv6 support. I'm going to enable it next week and will post the results here.
 
Sites such as google don't run only on IPv6; they also run on IPv4, or else youyr IPv4 system couldn't find them.

If they only worked on IPv4 they wouldn't have A records, since A records are only supported for IPv4. IPv6 use AAAA records.

Jeff
 
True Jeff, but for some reason it does cause PHP functions to be very slow with domainnames/servers that do support ipv6. I tried to include a domainname that only supports ipv4 and it works fine.

That's pretty strange right? (ok perhaps not but might explain why I think it has something to do with ipv6)
 
Do you have your system set up to support IPv6? Perhaps it's trying to find IPv6 first, and timing out? Other than that, I have no idea.

Jeff
 
No I haven't tried to setup my system yet with IPv6, I'm going to try that tomorrow and see if it will solve the problem.
 
I've finally been able to solve this problem for now.

Yesterday I've tried to enable ipv6 support on the server, but without any luck. I had to re-add all IP addressess (and remove/re-add the domainnames listed on the IP's) because I couldn't ping them anymore (and I only edited a couple of config files that seemed harmless)

I've been able to 'fix' the slow lookups by putting the openDNS nameservers in my /etc/resolv.conf

I really hope that DirectAdmin will support full ipv6 support in the near future. I'd love to enable ipv6 but right now it requires a lot of manual configing.

Thanks everyone for your help!
 
I've been able to 'fix' the slow lookups by putting the openDNS nameservers in my /etc/resolv.conf
Which indicates the problem was with resolution times on the nameservers you previously used.

Jeff
 
I saw many guides on google saying to disable ipv6 if you dont use it, when I searched for this problem.
 
Back
Top