I've got a CURL progress callback working via the CURLOPT_PROGRESSFUNCTION option which is successfully calling my member function in PHP. The dlnow variable is returning a correct received value, but dltotal always returns 0. What am I missing here?
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
}
}
EDIT: This post has been updated with info from @Sabuj Hassan. Originally I thought I was receiving a correct dltotal but an incorrect dlnow but I had an additional unnecessary argument in my callback function.
NOTE: for libcurl older than 7.32.0
the callback function need has the following format
where as newer curl binary does not require the resource
check your curl version version with
The problem seems to be that the website I'm requesting isn't sending an http content-length so dltotal is always empty. Thanks to @Subuj Hassan for correcting my error in my curl_progress_callback which had one too many values and made me originally think that the issue was with the dlnow value.
Try this with removing the class:
Then remove the first parameter from the
callback
.UPDATE: A working code: Try to run it from your end.