cURL启动时间慢 [英] cURL slow starttransfer_time
问题描述
Good Day!
在请求页面时,cURL的运行速度非常慢。我知道不是请求的页面,因为该页面会立即在浏览器中返回。
cURL is acting very slow when requesting a page. I know its not the page requested, because the page returns in the browser instantly.
我注意到的两件事
- starttransfer_time通常为20
- local_port似乎每次都在变化。
- 偶尔,cURL会立即响应
我有以下代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, false);
$output = curl_exec($ch);
curl_close($ch);
回显curl_getinfo()给我以下内容
Echoing curl_getinfo() gives me the following
[url] => http://127.0.0.1:80/wpengine/?json=t
[content_type] => text/html; charset=iso-8859-1
[http_code] => 302
[header_size] => 215
[request_size] => 64
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 17.238
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 221
[speed_download] => 12
[speed_upload] => 0
[download_content_length] => 221
[upload_content_length] => 0
[starttransfer_time] => 17.238
[redirect_time] => 0
[certinfo] => Array
(
)
[primary_ip] => 127.0.0.1
[primary_port] => 80
[local_ip] => 127.0.0.1
[local_port] => 51875
[redirect_url] =>
有人可以给我一些指示来弄清楚发生了什么吗?
Can anyone give me some pointers on how to figure out what is going on?
以下是Apache访问日志中的几行
Here are a few lines from the Apache access log
127.0.0.1 - - [06/Dec/2013:12:01:22 -0500] "GET /wpengine/?json=t HTTP/1.1" 302 221
127.0.0.1 - - [06/Dec/2013:12:01:12 -0500] "GET /community HTTP/1.1" 200 6266
127.0.0.1 - - [06/Dec/2013:12:01:22 -0500] "GET /public/js/jquery.js?b=10 HTTP/1.1" 304 -
推荐答案
这主要是因为期望:100连续
标头中的CURL在处理大型POST数据时发送到服务器,而服务器恰巧不支持此功能。您可以通过为 curl
命令行添加 -vv
来确认并查看输出。
This is mostly because of the Expect: 100-continue
header CURL send to the server when it handles large POST data, and the server just happened not support this feature. You can confirm by add -vv
for curl
command line and see the outputs.
要解决此问题,您可以
- 修复服务器以支持
预期:100 -continue
标头,或 - 强制卷曲不通过添加
-H Expect:
发送选项(在php中,您可以参考以下答案:如何我停止使用100继续使用cURL吗?)。
- fix your server to support
Expect: 100-continue
header, or - force curl not to send it by add
-H "Expect:"
option (in php, you can refer to this answer: How can I stop cURL from using 100 Continue?).
关于的链接预期:100-继续
:
https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3
https://support.urbanairship.com/entries/59909909-期望100-继续-问题与风险
这篇关于cURL启动时间慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!