Php - Progress bar script, Php progress in terminal using php

Progress bar script

The below script will help you see progress bar on your terminal. When we are doing some big task and it seems that the processing time will take some time in the background then we can use the progress bar on foreground. The below code will show progress status from 1 to 100

echo "Progress : "; // 5 characters of padding at the end
for ($i=0 ; $i<=100 ; $i++) {
echo "\033[5D"; // Move 5 characters backward
echo str_pad($i, 3, ' ', STR_PAD_LEFT) . " %"; // Output is always 5 characters long
sleep(1); // wait for a while, so we see the animation
}

This program is a progress bar script on termianl. Execute the program as below by providing the absolute path from your terminal.

# whereis php
php: /opt/lampp/bin/php


# /opt/lampp/bin/php /opt/lampp/htdocs/labs/index.php

The topic on Php - Progress bar script is posted by - Maha

Hope you have enjoyed, Php - Progress bar scriptThanks for your time

Tech Bluff