在使用CentOS系统时,许多用户可能会遇到通过curl访问外网地址速度缓慢的问题。导致这一现象的原因可能有很多,包括DNS解析问题、防火墙设置、网络配置或ISP的限制等。接下来云梦编程网为大家介绍CentOS中curl访问外网时速度慢的常见原因,并提供相应的解决方案,以帮助用户优化网络连接,有需要的小伙伴可以参一下:
1、测试响应速度:
curl-o/dev/null-s-w%{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}::%{speed_download}"\n"'https://www.yundreams.com'返回结果如下:
0.013::0.019::0.274::0.275::119281.000
参数解释:
| 字段 | 含义 |
|---|---|
| time_namelookup | DNS解析域名时间 |
| time_connect | client和server端建立TCP连接的时间 |
| time_starttransfer | 从client发出请求,到web的server响应第一个字节的时间 |
| time_total | client发出请求,到web的server发送会所有的相应数据的时间 |
| speed_download | 下载速度,单位byte/s |
2、解决方法一:升级libcurl
mkdir/tmp/libcurl&&cd/tmp/libcurl&&wgethttp://dl.fedoraproject.org/pub/archive/fedora/linux/updates/19/x86_64/curl-7.29.0-27.fc19.x86_64.rpm&&wgethttp://dl.fedoraproject.org/pub/archive/fedora/linux/updates/19/x86_64/libcurl-7.29.0-27.fc19.x86_64.rpm&&wgethttp://dl.fedoraproject.org/pub/archive/fedora/linux/updates/19/x86_64/libcurl-devel-7.29.0-27.fc19.x86_64.rpm&&yum-yinstall*.fc19.x86_64.rpm
然后重启php-fpm,因为我的是php的项目
servicephp-fpmrestart
3、解决方法二:
在/etc/resolv.conf的可选参数后里加上:single-request-reopen第一行内容既改为:optionstimeout:1attempts:1rotatesingle-request-reopen
以上就是云梦编程为大家介绍的关于Centos下curl执行慢的解决方法,了解更多相关文章请关注云梦编程网!
标签:




