title: PHP cURL - Get remaining time of download
body: <p>I am offering my users to use remote-upload to download the content directly on my server from (for example) their own server instead of local uploads. For that I'm using cURL. And now I want to get the remaining time cURL needs to complete the download (bitrate would be fine too).</p>
  
  <p>Is there a way I can return the remaining time cURL needs to finish the download via the PHP curl module or do I need to run the command-line interface and somehow put the output in a file and then read from there (since PHP blocks execution when using <code>shell_exec()</code> or <code>exec()</code>)?</p>
  
  <p>I'm already getting the bytes expected to download and how many curl already downloaded. This is the associated code as far:</p>
  
  <pre><code>function write_progress($ch, $original_size, $current_size, $os_up, $cs_up) {
      global $anitube, $cache;
  
      $cache-&gt;write("webupload-progress-".$anitube-&gt;input['inputname'], serialize(array("total" =&gt; $original_size, "loaded" =&gt; $current_size)));
  }
  
  ini_set('max_execution_time', '0');
  $handle_file = "/tmp/file-".$anitube-&gt;generate(20).".tmp";
  if(DIRECTORY_SEPARATOR == "\\") {
      $handle_file = IN_DIR.$handle_file;
  }
  
  $file = fopen($handle_file, "w+");
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, urldecode(trim($anitube-&gt;input['filename'])));
  curl_setopt($ch, CURLOPT_FILE, $file);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
  curl_setopt($ch, CURLOPT_NOPROGRESS, false);
  curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, "write_progress");
  if($anitube-&gt;users['ip'] == "127.0.0.1") {
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  }
  
  $data = curl_exec($ch);
  if(curl_errno($ch) &gt; 0) {
      file_put_contents(IN_DIR."/logs/curl_errors.txt", date("d.m.Y H:i:s")." - Errno: ".curl_errno($ch)." - Error: ".curl_error($ch)." -  cURL 4: ".print_r(curl_getinfo($ch), true)."\n", FILE_APPEND);
      die(json_encode(array("success" =&gt; 0, "response" =&gt; $language-&gt;word('remote_file_not_available'))));
  } elseif(curl_getinfo($ch, CURLINFO_HTTP_CODE) != 200) {
      file_put_contents(IN_DIR."/logs/curl_errors.txt", date("d.m.Y H:i:s")." - Error: Connection denied - HTTP-Response-Code: ".curl_getinfo($ch, CURLINFO_HTTP_CODE)." -  cURL 4: ".print_r(curl_getinfo($ch), true)."\n", FILE_APPEND);
      die(json_encode(array("success" =&gt; 0, "response" =&gt; $language-&gt;word('remote_file_not_available'))));
  }
  
  curl_close($ch);
  fclose($file);
  </code></pre>