1

When I navigate to http://maps.google.com/maps/api/geocode/json?address=1200+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false (the Google Maps Geocoding API test address) in my browser (Chrome), I get a json response as expected. However, when I drupal_http_request() the same url, I get a request timeout error. I tried setting the timeout to 60 instead of 30 but it doesn't help.

Why does drupal_http_request('http://maps.google.com/maps/api/geocode/json?address=1200+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false') return a timeout error?

3
  • What do you get for file_get_contents('http://maps.google.com/maps/api/geocode/json?address=1200+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false')? If that times out too the problem's probably environmental (network etc). It works fine from here using drupal_http_request
    – Clive
    May 1, 2015 at 0:10
  • Interesting. file_get_contents() also timed out for me. But drupal_http_request('http://drupal.stackexchange.com') doesn't time out, it works fine.
    – beth
    May 1, 2015 at 0:17
  • Might be DNS, you could try using Google's (8.8.8.8), may help if your ISP is having problems
    – Clive
    May 1, 2015 at 0:48

2 Answers 2

0

From everything mentioned, it sounds like a network issue; your web browser can reach the host @ maps.google.com but the server hosting Drupal can not. You can confirm this by trying to ping (ping maps.google.com) or telnet (telnet maps.google.com 80) maps.google.com on your server console.

With either command, you should get some sort of timeout or unknown host errors if that's truly what the problem is. This could happen for various reasons: server host firewall rules, Google blocking your server IP (e.g. a shared hosting env where someone is hammering maps.google.com), DNS lookup problems, etc.

1

You cannot directly include url queries in the url when using drupal_http_request(). Use url().

$url = url('http://maps.google.com/maps/api/geocode/json', ['query' => ['address'=>'1200 Amphitheatre Parkway, Mountain View, CA', 'sensor'=> FALSE]]);
drupal_http_request($url);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.