Skip to content

Instantly share code, notes, and snippets.

@shaneharter
Created December 5, 2012 01:32
Show Gist options
  • Save shaneharter/4211173 to your computer and use it in GitHub Desktop.
Save shaneharter/4211173 to your computer and use it in GitHub Desktop.
Progress Display for PHP CLI scripts
for ($i=1; $i<101; $i++) {
progress($i, 100, 'Percent Complete: ');
usleep(25000);
}
function progress ($step_x, $of_y, $label = '') {
$p = number_format($step_x / $of_y * 100, 1) . '%';
$p = str_pad($p, 5, ' ', STR_PAD_LEFT);
if ($label)
$p = "{$label} {$p}";
echo str_repeat("\010", strlen($p));
if ($step_x < $of_y)
echo $p;
else
echo str_repeat(' ', strlen($p)) . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment