Skip to content

Instantly share code, notes, and snippets.

@anon5r
Last active August 16, 2019 22:18
Show Gist options
  • Select an option

  • Save anon5r/8434d07da1301af8a6601711a35c1a7e to your computer and use it in GitHub Desktop.

Select an option

Save anon5r/8434d07da1301af8a6601711a35c1a7e to your computer and use it in GitHub Desktop.
コマンドラインでの進捗状況(プログレスバー)を表示する(PHP)
<?php
// 回転するやつ /-\|
$c=['|','/','-','\\'];
// like GCP
//$c=['⣤','⣆','⡇','⠏','⠛','⠹','⢸','⣰'];
$ci = count($c);
for($i=0;$i<=100;$i++){
echo "\r"; // 描画カーソルを行頭に戻す
$block=str_repeat('#',floor($i/5));
printf('Processing... %s [%-20s]%3d%%', $c[$i%$ci], $block, $i);
flush();
usleep(100000); // 表示用に適当なスリープ
}
// 出力行直後の改行
echo PHP_EOL;
@anon5r
Copy link
Copy Markdown
Author

anon5r commented Jul 5, 2016

実行結果はこんな感じから
Processing... - [#### ] 22%
こうなって
Processing... / [############# ] 65%
こうなる
Processing... | [####################]100%

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment