proxy prob!em using simplexml_load_file in php

浪尽此生 提交于 2019-12-11 04:49:21

问题


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://maps.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.


回答1:


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);



回答2:


Check your code

curl_close ($ch); 

should be the last line inside the function



来源:https://stackoverflow.com/questions/5498587/proxy-probem-using-simplexml-load-file-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!