proxy prob!em using simplexml_load_file in php
could somebody help me with this issue? I need to know in php latitude and longitude from an address.
I was doing:
$address = urlencode('my address');
$lat_lng = simplexml_load_file("http://m开发者_如何学运维aps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");
but I got this warning:
Message: simplexml_load_file() [function.simplexml-load-file]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution
I think I need to configure the proxy so I changed in this way:
$address = urlencode('my address');
$ch = curl_init("http://maps.google.com/maps/api/geocode/xml?address={$address}&sensor=false");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_PROXY, 'my_proxy);
curl_setopt($ch, CURLOPT_PROXYPORT, 'my+port');
$lat_lng = simplexml_load_string(curl_exec($ch));
curl_close($ch);
It seems to be blocked when I call curl_exec
.
Try w/o proxy settings first, it is probably error in proxy configuration.
function curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_close ($ch);
return curl_exec($ch);
}
$address = urlencode($address);
$data = curl("http://maps.google.com/maps/api/geocode/xml?address=$address&sensor=false");
$lat_lng = simplexml_load_string($data);
Check your code
curl_close ($ch);
should be the last line inside the function
精彩评论