当前位置: 首页 > 知识库问答 >
问题:

缓慢卷曲connect_time

巫新知
2023-03-14

在我的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) 
"" }

每天多次测试后,“连接时间”始终保持在50秒标记。我相信如果不是在1秒及以下,速度应该会快10倍。

我不知道服务器配置,但我被告知,我的服务器的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

Mem:2097152k,1273128k使用,824024k,0k缓冲区

交换:总共0千,使用0千,免费0千,缓存0千

我想知道这个问题的根源是什么?

编辑:附加信息

ping www.google。com结果。它似乎可以继续向前,所以我在第195行之后停止了命令

PINGwww.l.google.com(74.125.224.178)56(84)字节的数据。

来自lax02s01-in-f18的64字节。1e100。净(74.125.224.178):icmp_seq=1 ttl=56时间=12.0毫秒

来自lax02s01-in-f18的64字节。1e100。净(74.125.224.178):icmp_seq=2 ttl=56时间=12.1毫秒

64字节从lax02s01-in-f18.1e100.net(74.125.224.178):icmp_seq=3 ttl=56时间=11.9 ms

...

64字节从lax02s01-in-f18.1e100.net(74.125.224.178):icmp_seq=194 ttl=56时间=11.9 ms

64字节从lax02s01-in-f18.1e100.net(74.125.224.178):icmp_seq=195 ttl=56时间=11.9 ms

---www.l。谷歌。通信统计——发送195个数据包,接收194个数据包,0%数据包丢失,时间194711ms

跟踪路由。谷歌。com结果

Traceroute到www.google.com(74.125.224.180),最多30跳,60字节数据包

1 ip---*-。知识产权。安全服务器。净额(.*)0.585毫秒0.642毫秒0.778毫秒

2be10.trmd0215-01.ars.mgmt.phx3.gdg(208.109.112.126)0.599 ms 0.777 ms 0.893 ms

3 ip-97-74-253-122。知识产权。安全服务器。净(97.74.253.122)11.840毫秒12.119毫秒12.275毫秒

4 ip-97-74-253-122。知识产权。安全服务器。净(97.74.253.122)12.389毫秒12.482毫秒12.600毫秒

5 PR01。LAX03。谷歌。com(206.223.123.21)11.739 ms 11.709 ms 11.707 ms

6209.85.248.185(209.85.248.185)11.986 ms 11.797 ms 11.781 ms

772.14.236.11(72.14.236.11)12.606 ms 12.363 ms 12.328 ms

8lax02s01-in-f20.1e100.net(74.125.224.180)11.774 ms 11.864 ms 11.842 ms

共有2个答案

夹谷沛
2023-03-14

我刚刚运行了与您提供的配置相同的配置,并得到以下结果:

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)

我的猜测是,您的服务器连接本身可能存在带宽问题和/或被另一个进程以某种方式占用。

云炜
2023-03-14

尝试:

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); 

上述操作将阻止cURL首先尝试IPv6。

 类似资料:
  • 问题内容: 我正在OSX上尝试使用docker beta,主要用于Symfony开发,但是挂载的速度非常慢。即使对于香草Symfony项目,页面加载时间也只有6秒。难以忍受!有没有人找到解决此问题的方法?试图摆脱无业游民,但我只是找不到任何合理的方法来使用docker。 问题答案: 显然,目前有一种解决方法: https://forums.docker.com/t/file-access-in-m

  • 从DreamHost卷曲Facebook API是非常缓慢的。有时它会在1-2秒内回来,有时是20秒。它真的搞砸了我的网站。

  • 问题内容: 我想先查看请求中的帖子字段,然后再发送。(出于调试目的)。 我正在使用的PHP库(类)已经制作(不是我本人制作的),所以我试图理解它。 据我所知,它用于设置不同的选项(如标头等),然后用于发送请求。 关于如何查看正在发送哪些帖子字段的想法? 问题答案: 您可以启用以下选项: 当被设置时,输出写入 STDERR 或使用指定的文件。输出非常有用。 您还可以使用tcpdump或wirehar

  • 我安装了php7下载从repo的windows,所有工作良好。我正面临启用curl的问题。php_curl.dll文件存在于文本文件夹中,此扩展在php.ini中未注释,但此模块未显示在phpinfo中。 只有在运行php5时,我才能使用php7面对这个问题。x旋度很好用。正在寻找解决此问题的解决方案。这是php7本身的问题。是否有解决此问题的方法?

  • 我已经从postman手动运行了url,我已经成功连接并打印了结果。 但是当我试图从一个方法调用它时,没有结果是打印。 下面是我使用的curl代码: 下面是curl_log的内容。文本 > 主机名localhost/codeignitertest在DNS缓存中找到 尝试127.0.0.1... TCP_NODELAY集 连接到localhost/codeignitertest(127.0.0.1)