gpt4 book ai didi

php - 在我的 CURL CURLOPT_PROGRESSFUNCTION 回调中,dltotal 始终为 0

转载 作者:可可西里 更新时间:2023-11-01 00:44:43 28 4
gpt4 key购买 nike

我通过 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com