作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我通过 CURLOPT_PROGRESSFUNCTION 选项获得了一个 CURL 进度回调,它成功地调用了我在 PHP 中的成员函数。 dlnow 变量返回正确的接收值,但 dltotal 始终返回 0。我在这里缺少什么?
class MyClass {
function getFile(){
...
$fp = fopen ($file, 'w+');
$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,$signed['signed_url']);
curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
curl_setopt($curl, CURLOPT_FILE, $fp); // write curl response to file
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_NOPROGRESS, 0);
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, array($this, 'curl_progress_callback'));
}
function curl_progress_callback($dltotal, $dlnow, $ultotal, $ulnow){
echo $dltotal; //Reports correct value
echo $dlnow; //Always returns 0
}
}
编辑:这篇文章已根据来自@Sabuj Hassan 的信息进行了更新。最初我以为我收到了正确的 dltotal 但收到了不正确的 dlnow 但我的回调函数中有一个额外的不必要参数。
最佳答案
注意:对于早于 7.32.0 的 libcurl
回调函数需要有如下格式
curl_progress_callback($resource,$dltotal, $dlnow, $ultotal, $ulnow)
较新的 curl 二进制文件不需要资源
curl_progress_callback($dltotal, $dlnow, $ultotal, $ulnow)
检查你的 curl 版本
curl -V
关于php - 在我的 CURL CURLOPT_PROGRESSFUNCTION 回调中,dltotal 始终为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22417507/
我正在使用libcurl多接口(interface),我需要知道每个请求发送了多少数据。我宁愿不使用 CURLOPT_XFERINFOFUNCTION 因为它被多次调用,而我只需要在 CURLOPT_
我通过 CURLOPT_PROGRESSFUNCTION 选项获得了一个 CURL 进度回调,它成功地调用了我在 PHP 中的成员函数。 dlnow 变量返回正确的接收值,但 dltotal 始终返回
我是一名优秀的程序员,十分优秀!