[英]Curl slow sometimes
The same curl_exec is called every two seconds on my wamp server. 在我的wamp服务器上,每两秒钟调用一次相同的curl_exec。 In most cases the total_time is about 0.3 seconds, but in some cases (roughly every 30th call, but not deterministic) it is 8-9 secs.
在大多数情况下,total_time大约为0.3秒,但在某些情况下(大约每30次调用,但不是确定性的),则为8-9秒。
curl_getinfo (fast): curl_getinfo(快速):
[content_type] => application/json
[http_code] => 200
[header_size] => 141
[request_size] => 878
[filetime] => -1
[ssl_verify_result] => 20
[redirect_count] => 0
[total_time] => 0.312
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.156
[size_upload] => 635
[size_download] => 45528
[speed_download] => 145923
[speed_upload] => 2035
[download_content_length] => -1
[upload_content_length] => 635
[starttransfer_time] => 0.203
[redirect_time] => 0
[redirect_url] =>
curl_getinfo (slow): curl_getinfo(缓慢):
[content_type] => application/json
[http_code] => 200
[header_size] => 141
[request_size] => 878
[filetime] => -1
[ssl_verify_result] => 20
[redirect_count] => 0
[total_time] => 8.469
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.703
[size_upload] => 635
[size_download] => 51340
[speed_download] => 6062
[speed_upload] => 74
[download_content_length] => -1
[upload_content_length] => 635
[starttransfer_time] => 2.531
[redirect_time] => 0
[redirect_url] =>
Every case when total_time is high, starttransfer_time is also high. 在total_time高的每种情况下,starttransfer_time也高。 Additionally, pretransfer_time is higher while speed_download is lower than usual.
此外,pretransfer_time较高,而speed_download则较低。
I've tried: 我试过了:
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
and to use IP instead of the domain name in the URL, but did not solve the problem. 并使用IP代替URL中的域名,但并不能解决问题。
Has anyone any ideas on what could be causing this? 有谁对造成这种情况有任何想法?
I had a problem with slow cURL too. 我也遇到了缓慢的cURL问题。 I was implementing a "proxy" in PHP using cURL.
我正在使用cURL在PHP中实现“代理”。 I made a stupid mistake though:
我犯了一个愚蠢的错误:
In my case, the problem was in the "Content-Length" header, which I forwarded too. 就我而言,问题出在“ Content-Length”标头中,我也转发了该标头。
I made the payload shorter by replacing some values in the string. 我通过替换字符串中的一些值来缩短了有效负载。 I assume, that the cURL library was expecting more bytes to be sent.
我假设cURL库期望发送更多的字节。 This lead to a 20 - 30 seconds timeout.
这导致20到30秒的超时。
The fix was not to forward the "Content-Length" header too. 解决方法是也不要转发“ Content-Length”标头。 Hope this helps to some of you.
希望这对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.