skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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;
    
        }
    
    }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search