In my CURL CURLOPT_PROGRESSFUNCTION callback, dltotal is always 0
NOTE: for libcurl older than 7.32.0
the callback function need has the following format
curl_progress_callback($resource,$dltotal, $dlnow, $ultotal, $ulnow)
where as newer curl binary does not require the resource
curl_progress_callback($dltotal, $dlnow, $ultotal, $ulnow)
check your curl version version with
curl -V
Try this with removing the class:
curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, 'curl_progress_callback');
Then remove the first parameter from the callback
.
function curl_progress_callback($dltotal, $dlnow, $ultotal, $ulnow){ ...}
UPDATE: A working code: Try to run it from your end.
function getFile(){ $fp = fopen ("output.html", 'w+'); $curl = curl_init(); curl_setopt($curl,CURLOPT_URL,'http://www.mashable.com/'); curl_setopt($curl, CURLOPT_TIMEOUT, 1000); curl_setopt($curl, CURLOPT_FILE, $fp); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_NOPROGRESS, 0); curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, 'curl_progress_callback'); $result = curl_exec($curl); fclose($fp);}function curl_progress_callback($dltotal, $dlnow, $ultotal, $ulnow){ echo "$dltotal\n"; echo "$dlnow\n";}getFile();
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.