【发布时间】:2013-12-24 02:00:31
【问题描述】:
美好的一天!
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 -
【问题讨论】:
-
如果你在本地运行这个,你设置了什么服务器?你能检查一下服务器日志吗?
-
@r3mus 我正在使用 Apache 运行 Wamp。我编辑了我的帖子以包含访问日志中的几行
-
好奇 CURL 是否首先尝试 IPv6,但未能解决?尝试添加
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 ); -
嗯,这并没有什么不同。我觉得这很令人费解。它是否与会话有关,因为它位于同一域中?只是在黑暗中开枪......
-
不太确定,但是看看你的日志,一旦 CURL 真正命中服务器,它就超级快了。有什么方法可以在某处的公共服务器上尝试此操作以消除 localhost 变量?
标签: php performance curl