在我的VPS服务器上的php文件中考虑以下代码:
<?php $url = 'http://www.google.com';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; rv:1.7.3) Gecko/20041001 Firefox/0.10.1" );
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
$ci = curl_getinfo($ch);
curl_close($ch);
var_dump($ci); ?>
返回此
array(22) {
["url"]=> string(21) "http://www.google.com"
["content_type"]=> string(24) "text/html; charset=UTF-8"
["http_code"]=> int(200)
["header_size"]=> int(2055)
["request_size"]=> int(147)
["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0)
["total_time"]=> float(50.095466)
["namelookup_time"]=> float(0.001114)
["connect_time"]=> float(50.019724)
["pretransfer_time"]=> float(50.019825)
["size_upload"]=> float(0)
["size_download"]=> float(23156)
["speed_download"]=> float(462)
["speed_upload"]=> float(0)
["download_content_length"]=> float(-1)
["upload_content_length"]=> float(0)
["starttransfer_time"]=> float(50.070702)
["redirect_time"]=> float(0)
["certinfo"]=> array(0) { }
["redirect_url"]=> string(0)
"" }
在一天中的几个时间进行测试后,"connect_time"始终处于 50 秒标记。我相信如果不是在 10 秒及以下,它应该快 1 倍。
我不了解服务器配置,但我被告知我的服务器的 CPU 或 RAM 可能有故障。我使用顶部命令行显示以下内容,这对我来说似乎很好:
任务:共80个,1个正在运行,79个睡眠,0个停止,0个僵尸
CPU 处理器: 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
内存:总计 2097152k,已使用1273128k,免费824024k,0k 缓冲区
交换: 0k 总计, 0k 已使用, 0k免费, 0k 缓存
我想知道这个问题的根源是什么?
编辑:附加信息
ping www.google.com 结果。似乎它可以继续前进,所以我在第 195 行之后停止了命令
PING www.l.google.com (74.125.224.178) 56(84) 字节的数据。
来自 lax02s01-in-f18.1e100.net (74.125.224.178) 的 64 个字节:icmp_seq=1 ttl=56 时间=12.0 ms
来自 lax02s01-in-f18.1e100.net (74.125.224.178) 的 64 字节:icmp_seq=2 ttl=56 时间=12.1 ms
来自 lax02s01-in-f18.1e100.net (74.125.224.178) 的 64 个字节:icmp_seq=3 ttl=56 时间=11.9 ms
。
来自 lax02s01-in-f18.1e100.net (74.125.224.178) 的 64 个字节:icmp_seq=194 ttl=56 时间=11.9 ms
来自 lax02s01-in-f18.1e100.net (74.125.224.178) 的 64 个字节:icmp_seq=195 ttl=56 时间=11.9 ms
--- www.l.google.com ping统计---发送195个数据包,接收194个,0%丢包,时间194711ms
路由跟踪 wwww.google.com 结果
跟踪路由到 www.google.com (74.125.224.180),最多 30 跳,60 字节 包
1 个 ip---*-.ip.secureserver.net (.*..) 0.585 毫秒 0.642 毫秒 0.778 毫秒
2 be10.trmd0215-01.ars.mgmt.phx3.gdg (208.109.112.126) 0.599 毫秒 0.777 毫秒 0.893 毫秒
3 ip-97-74-253-122.ip.secureserver.net (97.74.253.122) 11.840 毫秒 12.119 毫秒 12.275 毫秒
4 ip-97-74-253-122.ip.secureserver.net (97.74.253.122) 12.389 毫秒 12.482 毫秒 12.600 毫秒
5 PR01.LAX03.google.com (206.223.123.21) 11.739 毫秒 11.709 毫秒 11.707 毫秒
6 209.85.248.185(209.85.248.185) 11.986 毫秒 11.797 毫秒 11.781 毫秒
7 72.14.236.11(72.14.236.11) 12.606 毫秒 12.363 毫秒 12.328 毫秒
8 lax02s01-in-f20.1e100.net (74.125.224.180) 11.774 毫秒 11.864 毫秒 11.842 毫秒
尝试:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
以上将阻止 cURL 首先尝试 IPv6。
我刚刚运行了您给出的相同配置并得到了以下内容:
array
'url' => string 'http://www.google.com' (length=21)
'content_type' => string 'text/html; charset=UTF-8' (length=24)
'http_code' => int 200
'header_size' => int 2079
'request_size' => int 151
'filetime' => int -1
'ssl_verify_result' => int 0
'redirect_count' => int 0
'total_time' => float 0.281
'namelookup_time' => float 0
'connect_time' => float 0
'pretransfer_time' => float 0
'size_upload' => float 0
'size_download' => float 23168
'speed_download' => float 82448
'speed_upload' => float 0
'download_content_length' => float -1
'upload_content_length' => float 0
'starttransfer_time' => float 0.187
'redirect_time' => float 0
'certinfo' =>
array
empty
'redirect_url' => string '' (length=0)
我的猜测是,您的服务器连接本身可能存在带宽问题和/或被另一个进程以某种方式征税。