Check out this cool little snippet for use in CLI scripts. It shows processing 
with a spinner. It took me a little while to figure out the magic combination 
of the cursor array and ternary operator. My main goal was to make it as self 
contained and efficient as possible. I am importing millions of records, and 
didn't want to waste CPU time on computing modulus on some huge $i value. :)

--------------------- 8< SNIP >8 ----------------------------------------------

#!/usr/bin/php -q
<?php
define('ESC', 27);
printf( "%c[2J", ESC ); //clear screen

//note how the '-' is at [1], not [0]
$cursorArray = array('/','-','\\','|','/','-','\\','|'); 

echo "Processing: ";

printf( "%c7", ESC ); //save cursor position

for ($count = 1; $count <= 30; $count++) 
{
        //note that $i is all self contained.
        printf("%c8(".$cursorArray[ (($i++ > 7) ? ($i = 1) : ($i % 8)) ].") 
%02d", ESC, $count); //restore cursor position and print
        sleep(1);
}

echo "\nDone.\n";
?>

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to