Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

file_get_contents hangs

I am using Google GeoCoding services. I have a PHP application which calls the Google Maps API, and receives JSON data. The function which calls Google Maps host hangs until it times out, but only when I push to Godaddy Virtual Private server.

I have already ssh'd into the server and edited php.ini I changed "safe mode" to "off"

I get this error message:

Message: file_get_contents(http://maps.googleapis.com/maps/api/geocode/json?address=xYxY&sensor=false): failed to open stream: Connection timed out

This works fine in my WAMP server but fails on live server. Any ideas why?

like image 766
GRY Avatar asked Jun 20 '12 06:06

GRY


1 Answers

I have found the answer. What has been a week, now? I hope others find this solution. The virtual dedicated servers from GoDaddy are ipv6 enabled, but google maps API is having none of that. So tell Curl to force v4 request, like this:

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );

credit is due in part to a blog where I found this information:

http://www.businesscorner.co.uk/disable-ipv6-in-curl-and-php/

like image 63
GRY Avatar answered Sep 19 '22 14:09

GRY