大网数据广告活动
服务器运维问答

Slow Responses with curl and wget on CentOS 7

· 52CE 我爱测

My problem is that I cannot figure out why I'm getting such slow response times using curl and wget. When I say slow, I mean a minimum of five or six seconds for a page which should take only a second or less. I've tested all kin…

问题原文

原帖链接 · SuperDog · CC BY-SA 3.0

My problem is that I cannot figure out why I'm getting such slow response times using curl and wget. When I say slow, I mean a minimum of five or six seconds for a page which should take only a second or less.

I've tested all kinds of scenarios, but I can't seem to make any difference at all.

My server is: CentOS Linux release 7.3.1611 (Core)

I'm trying to fix this because it is slowing down a newly installed WordPress application. I ended up identifying (using Xdebug) that, rather than the problem being WP, it appears to be PHP calls which use curl. Subsequently I've been testing from the command line, without any other application.

So, for example:

$ curl -o /dev/null "http://techrepublic.com"
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                             Dload  Upload   Total   Spent    Left  Speed
  100   178  100   178    0     0     30      0  0:00:05  0:00:05 --:--:--    41

It doesn't make any difference what the URL is, but if I use an IP address, instead of a domain name, then there's no problem at all.

The same problem is also true using wget.

So, some of the things I've tried are:

  • a) Changing the DNS servers in /etc/resolv.conf
  • b) Same effect with curl and also with wget
  • c) Same effect with both http and also with https
  • d) Same effect with both heavy and lightweight pages
  • e) Tested with curl on Windows 10, on same network, with same router, etc, and it takes about a second or less
  • f) Tested as a regular user, and as root

My primary DNS server is now listed in /etc/resolv.conf as 8.8.8.8, which should be fine.

To get more information, I also used this:

$ curl -L --output /dev/null --silent --show-error --write-out 'lookup: %{time_namelookup}\nconnect:%{time_connect}\nappconnect:%{time_appconnect}\npretransfer:%{time_pretransfer}\nredirect:%{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal:%{time_total}\n' 'techrepublic.com'
Output:
lookup: 5.514
connect:5.528
appconnect:0.000
pretransfer:5.528
redirect:5.819
starttransfer: 6.680
total:12.552

(not sure why, but using curl this way seems to take longer than using it without all the options, but either way it's still taking far too long)

So, I'm figuring that somehow, somewhere, this is related to DNS lookups, but I'm really not sure what else to try. It's very frustrating.

Any assistance would be greatly appreciated. Thanks!

已采纳解答

原帖链接 · SuperDog · CC BY-SA 3.0

Okay, problem solved. After delving into the web again for similar problems I came upon this site, which described the same issue:

http://aarvik.dk/disable-ipv6/

Adding the following line to the bottom of /etc/resolv.conf resolved the issue for me, but I recommend you read the article in full:

options single-request-reopen

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。