show progress in terminal using php

by Guna 2011-10-10 12:48:15

Hi,

While we doing any big tasks in the background, some time we're interested to know how much it is completed and how much time it'll
take to complete the whole task.

Most of the time we do run these process in terminal as a background process. so that time we need to know above said things. Following
code will show you process 1 to 100 in terminal.

This is only a sample code, you've to update it according to your reqirements,


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
}



Run this program in terminal by giving absolute path like,

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

Tagged in:

752
like
0
dislike
0
mail
flag

You must LOGIN to add comments