douguang9014 2015-05-05 10:56
浏览 96
已采纳

php cURL进度函数大小限制

I'm downloading a file using cURL 7.38.0 with php 5.6 and I'd like to get the download progress. This is my code:

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://path/to/file.zip");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BUFFERSIZE, 65536);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'downloadProgress'); 
curl_setopt($ch, CURLOPT_NOPROGRESS, false);

curl_exec($ch);
curl_close($ch);

function downloadProgress ($resource, $download_size, $downloaded_size, $upload_size, $uploaded_size) {
    echo 'download_size: ' . $download_size . '; downloaded_size: ' . $downloaded_size . ';<br>';
}

Everything works fine most of the time except that if the file is bigger than 2GB, then $download_size returns -2147483648 and $downloaded_size works until it gets to 2147483648 and also turns to -2147483648 and stops incrementing.

The output with a 3.4GB file is the following:

download_size: 0; downloaded_size: 0;
download_size: -2147483648; downloaded_size: 1147;
download_size: -2147483648; downloaded_size: 1147;
download_size: -2147483648; downloaded_size: 16987;
download_size: -2147483648; downloaded_size: 16987;
download_size: -2147483648; downloaded_size: 25627;
...
download_size: -2147483648; downloaded_size: -2147483648;
download_size: -2147483648; downloaded_size: -2147483648;
download_size: -2147483648; downloaded_size: -2147483648;

Is there something I have done wrong or is it a php cURL limitation?

Thank you.

  • 写回答

1条回答 默认 最新

  • douhan9748 2015-05-05 11:23
    关注

    CURLOPT_PROGRESSFUNCTION function argument type are double, so you are probably casting these value to int somewhere in your code. and probably since your os is 32bit based architecture you are overflowing the int size limit. I would suggest you revise your code to avoid casting to int big double numbers.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?