Last active
          November 6, 2015 12:41 
        
      - 
      
- 
        Save Bouhnosaure/73dabd5b7e17ebc06f8a to your computer and use it in GitHub Desktop. 
    Console status bar
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| public function show_status($done, $total, $size = 50) | |
| { | |
| static $start_time; | |
| // if we go over our bound, just ignore it | |
| if ($done > $total) return; | |
| if (empty($start_time)) $start_time = time(); | |
| $now = time(); | |
| $perc = (double)($done / $total); | |
| $bar = floor($perc * $size); | |
| $status_bar = "\r["; | |
| $status_bar .= str_repeat("=", $bar); | |
| if ($bar < $size) { | |
| $status_bar .= ">"; | |
| $status_bar .= str_repeat(" ", $size - $bar); | |
| } else { | |
| $status_bar .= "="; | |
| } | |
| $disp = number_format($perc * 100, 0); | |
| $status_bar .= "] $disp% $done/$total"; | |
| $rate = ($now - $start_time) / $done; | |
| $left = $total - $done; | |
| $eta = round($rate * $left, 2); | |
| $elapsed = $now - $start_time; | |
| $status_bar .= " remaining: " . number_format($eta) . " sec. elapsed: " . number_format($elapsed) . " sec."; | |
| echo "$status_bar "; | |
| flush(); | |
| if ($done == $total) { | |
| echo "\n"; | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment