Monday 4 February 2019

Command line progress bar in PHP

I am currently trying to add a progress bar to a command line script and I've tried various solutions (including Zend and Console_ProgressBar). The problem they both have in common is that the progress bar doesn't stick at the bottom of the window because during the script, new lines and other information is outputted.



Is there any way to keep the progress bar at the bottom of the terminal but still be able to output other information while the script is running?




[Edit]



I figured it out:



Instead of outputting directly to STDOUT I am actually grabbing the output inside a variable, I erase the screen with echo chr(27) . '[2J' and then output to STDOUT the contents of the variable and then append my progress bar.



Hope that makes sense :)

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...