php cURL - 上传限制缓慢 - 如何优化?

时间:2013-03-04 10:33:24

标签: php curl

我正在使用cURL在我的网站和合作伙伴的网站之间传输数据。

请求很长(约18秒),但信息量很小(~207字节)。

以下是我生成请求的代码:

// Send the subscription           
$resource = curl_init($url);
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_POST, count($postFields));
curl_setopt($resource, CURLOPT_POSTFIELDS, $postString);
$result = curl_exec($resource);

以下是curlinfo调试的结果:

17.418212 total_time : Total transaction time in seconds for last transfer
0.064612 namelookup_time : Time in seconds until name resolving was complete
0.437222 connect_time : Time in seconds it took to establish the connection
0.946509 pretransfer_time : Time in seconds from start until just before file transfer begins
17.418172 starttransfer_time : Time in seconds until the first byte is about to be transferred
0 redirect_count : Number of redirects
0 redirect_time : Time in seconds of all redirection steps before final transaction was started
207 size_upload : Total number of bytes uploaded
11 speed_upload : Average upload speed
130 size_download : Total number of bytes downloaded
7 speed_download : Average download speed 

关于curlinfo文档:http://curl.haxx.se/libcurl/c/curl_easy_getinfo.html,据说size_upload和speed_upload分别以字节和字节/秒为单位。

10字节/秒不是很快,是吗? 我在哪里可以找到其他调试信息,我可以做些什么来提高这个速度?

其他信息: 发送和接收数据的服务器都具有良好的带宽 两者都在同一个城市

1 个答案:

答案 0 :(得分:0)

它看起来像服务器端的性能问题。

curl_getinfo()报告的速度计算如下:

bytesPerSecond = totalBytesReceived/totalTime

其中totalTime是curl_exec执行时间。

如果服务器响应延迟(服务器忙等)你可能需要等待1分钟才能获得最后一毫秒的60字节,报告的速度将是每秒1字节,服务器之间的网络连接速度并不重要。