tags:

views:

1697

answers:

4

My web page uses Google charts to produce five graphs. If the graphs are not already cached, I have the following line of code that retrieves the image.

$image = file_get_contents("http://chart.apis.google.com/chart?".$query);

When that code is executed in a loop, it takes 10 seconds to get each image. But, if I change the code as to use one of Google's ip addresses instead of the url:

$image = file_get_contents("http://74.125.93.100/chart?".$query);

It takes less than one second to retrieve the images. So my initial thought was that DNS is not resolving the URL and the delay is from cycling through the assigned DNS servers? So I tried to ping chart.apis.google.com from the server and it immediately returned a reasonable response.

So my question is: Is there any PHP (or Apache2) configuration setting that I may be overlooking that may cause this delay, or does this sound like a server configuration issue?

A: 

Why not resolve the ip before start to load the images?

$ip = gethostbyname($name);
$image = file_get_contents($ip."/chart?".$query);
Hippo
Yes, that would work but would still cost ~10 seconds which is unacceptable. I'm convinced its a config issue, just not sure if it sounds like a PHP, Apache, or server config issue.
Kevin
It would work only if on that server is hosted only one site. In multisite environment server would'n know which site are you calling
Alekc
+4  A: 

Your DNS resolving is slow (the DNS your server is using can be a broblem, then most of the other domains could be slow) or your server has problems using the DNS cache.

In any case, if you don't have some specific reasons to manipulate the image received from google charts, why don't you just print out it as an img tag? You can overlay texts or transparent png-s with css if you want.

Csaba Kétszeri
A: 

Which version of the HTTP protocol are you using?

+2  A: 

Got the same problem here. It might be a DNS issue... maybe the apache server which use DNS servers that are too slow.

i have tried differents ways: CURL, WGET (shell exec)... and still got the same performance issue.

It takes about 15 seconds on my production server. But on my local server (which uses IP) takes less than 1.5 seconds with my script.

try /etc/resolv.conf or /etc/named.conf? maybe. I am trying to find a solution.

I had the same exact problem as you, it seems. My solution turned out to be editing my /etc/resolv.conf to use Google's nameservers (i.e. `nameserver 8.8.8.8`).
Steven Oxley