gpt4 book ai didi

php - cURL 慢启动传输时间

转载 作者:行者123 更新时间:2023-12-05 09:23:36 27 4
gpt4 key购买 nike

美好的一天!

请求页面时,cURL 的运行速度非常慢。我知道这不是请求的页面,因为该页面会立即返回到浏览器中。

我注意到的两件事

  • 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() 给我以下信息

[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] =>

谁能给我一些关于如何弄清楚发生了什么的指示?

这里有几行来自 Apache 访问日志

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 -

最佳答案

这主要是因为 Expect: 100-continue header CURL 在处理大型 POST 数据时发送到服务器,而服务器恰好不支持此功能。您可以通过为 curl 命令行添加 -vv 来确认并查看输出。

要解决这个问题,您可以

  1. 修复您的服务器以支持 Expect: 100-continue header ,或
  2. 通过添加 -H "Expect:" 选项强制 curl 不发送它(在 php 中,您可以引用这个答案:How can I stop cURL from using 100 Continue?)。

关于 Expect: 100-continue 的链接:

https://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3 https://support.urbanairship.com/entries/59909909--Expect-100-Continue-Issues-and-Risks

关于php - cURL 慢启动传输时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20428632/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com