解决办法,就是设置2个参数
CURLOPT_LOW_SPEED_LIMIT?
CURLOPT_LOW_SPEED_TIME
解释如下:
CURLOPT_LOW_SPEED_LIMIT | 当传输速度小于CURLOPT_LOW_SPEED_LIMIT时(bytes/sec),PHP会根据CURLOPT_LOW_SPEED_TIME来判断是否因太慢而取消传输。 | | CURLOPT_LOW_SPEED_TIME | 当传输速度小于CURLOPT_LOW_SPEED_LIMIT时(bytes/sec),PHP会根据CURLOPT_LOW_SPEED_TIME来判断是否因太慢而取消传输。 |
官方原文是这里:CURLOPT_LOW_SPEED_TIME
大致意思就是注释这里,就是下载在xx秒内,多少个字节,就断开连接了,这样就不会卡在某个地方了
/* abort if slower than 30 bytes/sec during 60 seconds */
代码如下:
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, url);
/* abort if slower than 30 bytes/sec during 60 seconds */
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 60L);
curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 30L);
res = curl_easy_perform(curl);
if(CURLE_OPERATION_TIMEDOUT == res) {
printf("Timeout!\n");
}
/* always cleanup */
curl_easy_cleanup(curl);
}
|