With below code
curl_setopt($ch, CURLOPT_NOPROGRESS, 0);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, 'progress_upload');
progress_upload function will be triggered many times in a second but how can we set an interval to decrease it?
You can also use a tiny trick in your body function like below
function progress_upload()
{
//contain time of next run
static $next ;
$INTERVAL = 5; // unit is second
$now = time();
if ( $now > $next ){
//function body here
//
//
//
$next = $now + $INTERVAL;
}
}
static $next = 0;. If you replace $next = $now + $INTERVAL; by $next += $INTERVAL; you use $now only once, so you can simply replace it by time(). Simpler is better.I believe you want to set the BUFFERSIZE (in bytes) so that it will download in larger chunks:
curl_setopt($ch, CURLOPT_BUFFERSIZE, 2048);
Note: Someone mentioned that CURLOPT_PROGRESSFUNCTION is deprecated, I can see that how it works changes after 5.5.0 - but nowhere can I see that this feature will be removed.
CURLOPT_PROGRESSFUNCTIONis deprecated.