Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.