Skip to content

Instantly share code, notes, and snippets.

@freemanirl
Created June 27, 2014 16:14
Show Gist options
  • Save freemanirl/b9815028584e33dbcca5 to your computer and use it in GitHub Desktop.
Save freemanirl/b9815028584e33dbcca5 to your computer and use it in GitHub Desktop.
Something to try and do a progress bar.
public function showProgress($total, $current, $message = '')
{
$this->cachedMessage = str_repeat("\x08", strlen($this->cachedMessage));
$percentComplete = ($current/$total);
$completedCharacters = ceil($percentComplete * $this->totalProgressCharacters);
$bar = str_repeat("*", $completedCharacters);
$bar = str_pad($bar, $this->totalProgressCharacters, " ");
$bar = "[" . $bar . "] ";
$formatter = new \NumberFormatter('en_US', \NumberFormatter::PERCENT);
$this->cachedMessage .= $bar . $formatter->format($percentComplete) . ($message ? " - " . $message : '');
$this->logger->info($this->cachedMessage);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment