PHP-CLI 多行进度条
来源:互联网 发布:centos mirror 编辑:程序博客网 时间:2024/06/03 16:30
我们使用PHP运行任务的时候,通常需要查看进度。要是能有一个像下载进度条一样直观的图就更好了。于是我做了一个。
<?php/*** ______ __ ____ __ * /_ __/__ ____/ / ___ ___ / _(_)__ ___ ___/ / * / / / -_) __/ _ \/ _ \/ _ \/ _/ / -_) _ \/ _ / * /_/ \__/\__/_//_/_//_/\___/_//_/\__/_//_/\_,_/ * ___ ___ ___ _______ ______________________ * |_ ||_ |( _ < / __// __< < / __< / ___ \___ ____ _ _______ __ _ * / __// __// _ / /__ \/__ \/ // /__ \/ / / _ `/ _ `/ _ `// __/ _ \/ ' \* /____/____/\___/_/____/____/_//_/____/_/\ \_,_/\_, /\_, (_)__/\___/_/_/_/* \___/ /_/ /_/ * 作者:Technofiend <2281551151@qq.com>* 多进度条输出*/ini_set('max_execution_time', '0');$percentStatus = [];// 组合成进度条function buildLine($percent) { $repeatTimes = 100; if ($percent > 0) { $hasColor = str_repeat('■', $percent); } else { $hasColor = ''; } if ($repeatTimes - $percent > 0) { $noColor = str_repeat(' ', $repeatTimes - $percent); } else { $noColor = ''; } $buffer = sprintf("[{$hasColor}{$noColor}]"); if ($percent !== 100) { $percentString = sprintf("[ %-6s]", $percent . '%'); } else { $percentString = sprintf("[ %-5s]", 'OK');; } return $percentString . $buffer . "\r";}// 输出进度条function outputProgress($clear = false){ global $percentStatus; if ($clear) { $number = count($percentStatus); for ($i=0; $i < $number; $i++) { system("tput cuu1"); system("tput el"); } } foreach ($percentStatus as $value) { echo buildLine($value) . "\n"; }}// 更新进度条值function updateProgressValue($k, $value) { $percentStatus[$k] = $value; if ($percentStatus[$k] >= 100) { $percentStatus[$k] = 100; outputProgress(true); return; } outputProgress(true); usleep(50000);}$percentStatus[0] = 0;$percentStatus[1] = 0;$percentStatus[2] = 0;$percentStatus[3] = 0;$percentStatus[4] = 0;$percentStatus[5] = 0;$percentStatus[6] = 0;$percentStatus[7] = 0;$percentStatus[8] = 0;outputProgress();while(1) { $percentStatus[0] = rand(0, 100); $percentStatus[1] = rand(0, 100); $percentStatus[2] = rand(0, 100); $percentStatus[3] = rand(0, 100); $percentStatus[4] = rand(0, 100); $percentStatus[5] = rand(0, 100); $percentStatus[6] = rand(0, 100); $percentStatus[7] = rand(0, 100); $percentStatus[8] = rand(0, 100); outputProgress(true); usleep(500000);}
大家可以复制上面代码,保存成为run.php
然后在linux下 运行 php run.php
阅读全文
0 0
- PHP-CLI 多行进度条
- php cli多进程
- 仿微信中加载网页时带线行进度条的WebView的实现
- 仿微信中加载网页时带线行进度条的WebView的实现
- 仿微信中加载网页时带线行进度条的WebView的实现
- 仿微信中加载网页时带线行进度条的WebView的实现
- 仿微信中加载网页时带线行进度条的WebView的实现
- PHP CLI
- php cli详情
- PHP CLI模式
- PHP CLI and Cron
- PHP SAPI---CLI
- PHP SAPI---CLI
- PHP CLI模式开发
- php的cli简介
- PHP CLI 传递参数
- PHP SAPI---CLI
- PHP-CLI 简介
- 偏最小二乘法回归(Partial Least Squares Regression)
- TensorFlow学习系列(三):保存/恢复和混合多个模型
- redux添加中间件
- 【开发笔记】Solr 6.5.1 Windows x64服务器部署笔记(含中文分词和业务字段定义)
- 建模工具
- PHP-CLI 多行进度条
- hibernate下hql与sql查询结果的问题
- Jmeter之Bean shell使用(一)
- nginx-视频直播和点播服务的干货分享
- jsp 解决ajax乱码的问题
- ZZULIOJ 1726 迷宫【状压Bfs+巨多的坑】
- vue-cli与webpack结合如何处理静态资源
- 上传文件控制input type="file"样式修改记
- 2.LocalDateTime、LocalDate