我的curl执行时间非常长,我在另一台服务器上运行相同的代码并且有非常不同的结果:这些是差异:
卷曲执行时间长的服务器
{
"url": "http://maps.googleapis.com/maps/api/geocode/json?latlng=45.644843,8.9986268&sensor=false",
"content_type": "application/json; charset=UTF-8",
"http_code": 200,
"header_size": 377,
"request_size": 119,
"filetime": -1,
"ssl_verify_result": 0,
"redirect_count": 0,
"total_time": 127.26954,
"namelookup_time": 0.001964,
"connect_time": 127.23926,
"pretransfer_time": 127.239265,
"size_upload": 0,
"size_download": 11729,
"speed_download": 92,
"speed_upload": 0,
"download_content_length": -1,
"upload_content_length": 0,
"starttransfer_time": 127.269424,
"redirect_time": 0,
"certinfo": []
"request_header":"GET \/maps\/api\/geocode\/json?latlng=45.644843,8.9986268&sensor=false HTTP\/1.1\r\nHost: maps.googleapis.com\r\nAccept: *\/*\r\n\r\n"
}
卷曲执行时间短的服务器
{
"url": "http://maps.googleapis.com/maps/api/geocode/json?latlng=45.644843,8.9986268&sensor=false",
"content_type": "application/json; charset=UTF-8",
"http_code": 200,
"header_size": 377,
"request_size": 119,
"filetime": -1,
"ssl_verify_result": 0,
"redirect_count": 0,
"total_time": 0.116182,
"namelookup_time": 0.012194,
"connect_time": 0.027452,
"pretransfer_time": 0.027473,
"size_upload": 0,
"size_download": 11729,
"speed_download": 100953,
"speed_upload": 0,
"download_content_length": -1,
"upload_content_length": 0,
"starttransfer_time": 0.114101,
"redirect_time": 0,
"redirect_url": "",
"primary_ip": "172.217.**.**",
"certinfo": [],
"primary_port": 80,
"local_ip": "192.168.**.**",
"local_port": 51393
"request_header":"GET \/maps\/api\/geocode\/json?latlng=45.644843,8.9986268&sensor=false HTTP\/1.1\r\nHost: maps.googleapis.com\r\nAccept: *\/*\r\n\r\n"
}
我的服务器有什么问题?我注意到在第一种情况下没有ip引用!
这是服务器代码:
<?php
$latitudine = 45.644842999999995;
$longitudine = 8.9986268;
$geoloca = $latitudine.",".$longitudine;
$request = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$geoloca.'&sensor=false';
$file_contents = url_get_contents($request);
function url_get_contents($Url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
$output = curl_exec($ch);
$info = curl_getinfo($ch);
echo(json_encode($info));
curl_close($ch);
return $output;
}
?>