Curl_exec error: Couldn't resolve host

Status
Not open for further replies.

belltown

Member
Messages
97
Reaction score
4
Points
8
I have a PHP script which uses cURL to retrieve maps from Google. Until yesterday it was working fine. Now, every once in while I get a curl error: "Couldn't resolve host 'maps.google.com'". Some of the time it works, some of the time it doesn't.

Here is a short script that reproduces the problem:

Code:
<?php
/*
 * [URL]http://belltown.x10hosting.com/test.php[/URL]
 */
$url = "[URL]http://maps.google.com/maps/api/staticmap[/URL]?".
          "center=seattle,wa&".
          "zoom=13&".
          "size=640x640&".
          "maptype=roadmap&".
          "format=jpg&".
          "mobile=true&".
          "sensor=false";
if (($c = curl_init ($url)) === false) die ("curl_init error: ".curl_error ($c));
if (curl_exec ($c) === false) die ("curl_exec error: ".curl_error ($c));
 
curl_close ($c);          
?>

Sometimes it returns a map, sometimes it returns the following error:

Code:
curl_exec error: Couldn't resolve host 'maps.google.com'

I wonder if this is related to the problems absolut has been having lately. Any ideas?
 

belltown

Member
Messages
97
Reaction score
4
Points
8
Upon further investigation, it appears that the DNS resolution on the absolut Apache server is not working consistently. Here's another test script show that 2 out of 10 times, the server failed to return a valid IP address when gethostbyname was called from a PHP script.

Here's the script:

Code:
<?php
/*
 * [URL]http://belltown.x10hosting.com/test.php[/URL]
 */
$host = 'maps.google.com';
echo "Looking up: $host<br><br>";
for ($i = 0; $i < 10; $i++) {
 $ip = gethostbyname($host);
 if ($ip == $host) {
  echo "Unable to resolve host name<br>";
 }
 else {
  echo "IP address: $ip<br>";
 }
 sleep (5);
}
?>

And here's the output:

Code:
Looking up: maps.google.com
 
IP address: 74.125.95.104
IP address: 74.125.95.147
IP address: 74.125.95.103
Unable to resolve host name
IP address: 74.125.95.105
Unable to resolve host name
IP address: 74.125.95.99
IP address: 74.125.95.147
IP address: 74.125.95.105
IP address: 74.125.95.106
 
Status
Not open for further replies.
Top