Skip to content

Instantly share code, notes, and snippets.

@Thijzer
Created April 17, 2018 21:36
Show Gist options
  • Save Thijzer/ae221a5de6254f903e2235f00db4af43 to your computer and use it in GitHub Desktop.
Save Thijzer/ae221a5de6254f903e2235f00db4af43 to your computer and use it in GitHub Desktop.
<?php
function echoProgressBar(int $totalAmount, int $progress, int $parts = 100)
{
if ($totalAmount === $progress) {
echo sprintf("[%s] %s %s %%", str_repeat('#', $parts), $progress, 100);
return;
}
$quota = 100 / $parts;
$percent = round($progress / $totalAmount * 100);
$line = round($percent / $quota);
$progressBar = str_repeat('#', $line);
$progressBar .= str_repeat('_', $parts - $line);
echo sprintf("[%s] %s %s %% \r", $progressBar, $progress, $percent);
}
$productsCount = 6245;
for ($i=0 ; $i<=$productsCount ; $i++) {
echoProgressBar($productsCount, $i, 150);
usleep(1 * 1000); // mssleep
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment