title: Get remaining time execution of php script
body: <p>I am trying to get the current remaining time of an execution php script.</p>
  
  <p>I tried:</p>
  
  <pre><code>$urls1 = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
  $total_urls = count($urls1);
  foreach ($urls1 as $url) {
    $start_time = microtime(true);
    // here I do some things
    $time_end = microtime(true);
    $execution_time = $time_end - $start_time;
    $current_urls_remaining = $total_urls - 1;
    $total_time = $current_urls_remaining * floatval($execution_time);
    $timeleft = $total_time - floatval($execution_time);
    $db-&gt;query("UPDATE sessions SET timeleft = '$timeleft'");
  }
  </code></pre>
  
  <p>// the problem is that it's updated with random numbers</p>
  
  <p>EXPECTED OUTPUT</p>
  
  <pre><code> Iteration 1 - Remaining approximate time let's say 5 second
   Iteration 2 - Remaining approximate time 4 seconds
   Iteration 3 - Remaining approximate time 3.5 seconds
   ...
  </code></pre>
  
  <p>I am pretty sure I am mistaking the formula for doing this, If anyone could help with an example would be much appreciated. I am not talking about inventing artificial intelligence just need an example on how to get the remaining time.</p>