承接 nickbeen/php-cli-progress-bar 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nickbeen/php-cli-progress-bar

Composer 安装命令:

composer require nickbeen/php-cli-progress-bar

包简介

For creating minimal progress bars in PHP CLI scripts

README 文档

README

Latest version Build status Total downloads PHP Version License

For creating minimal progress bars in PHP CLI scripts. It has no dependencies, but requires PHP 8.0 or higher. This library is mainly built for iterating to countable variables, but also works easily with ticking through less structured step-by-step scripts.

Many PHP CLI progress bars have been written in the past, but most haven't been updated in years. This library uses the latest PHP features such as return types, named arguments and constructor property promotions. For creating richer, more customizable progress bars, check alternatives such as the progress bar helper included in the symfony/console package.

Requirements

  • PHP 8.0 or higher

Installation

Install the library into your project with Composer.

composer require nickbeen/php-cli-progress-bar

Usage

With this library you can display a progress bar in a PHP CLI script to indicate the script is doing its work and how far it has progressed. All you need to do is start displaying the progress bar, tick through the steps the script goes through and finish the display of the progress bar.

  1/100 [#...........................]   1% (00:00:16)
 64/100 [##################..........]  64% (00:00:07)
100/100 [############################] 100%

Manually progressing

It is possible to tick through the steps of your scripts manually when the steps in your script cannot be looped. Each tick adds one progression, but you can override the progression made by including an integer in tick().

You do need to set maxProgress for the progress bar to display the correct numbers by including it in the constructor. If you don't know the maxProgress during initialization, you can set it later with the setMaxProgress() method.

$progressBar = new \NickBeen\ProgressBar\ProgressBar(maxProgress: 62);
$progressBar->start();

doSomething();
$progressBar->tick();

doSomethingElse();
$progressBar->tick();

doSixtyTasks();
$progressBar->tick(60);

$progressBar->finish();

If you have a little more structure in your step-by-step code, you can easily place tick() in a for loop. There is however a more convenient method when dealing with e.g. arrays.

Iterating through arrays or traversable instances

This class method works with anything of the pseudo-type iterable which includes any array or any instance of Traversable. The iterate() method automatically handles starting the progress bar, managing ticking through the iteration and finally finish displaying the progress bar.

$array = [
    1 => 'A',
    2 => 'B',
    3 => 'C',
];

$progressBar = new \NickBeen\ProgressBar\ProgressBar();

foreach ($progressBar->iterate($array) as $key => $value) {
    echo "$key: $value" . PHP_EOL;
}

Interact with the progress bar

It is possible to interact with the progress bar during its run. You can retrieve the estimated time to finish, the progress it has made, the maximum progress that has been set and the amount of completion in percentage. You can use this information e.g. for notifications or other tasks in the background.

foreach ($progressBar->iterate($array);) {
    // Some custom notification
    sendToDiscord($progressBar->getEstimatedTime());

    // Some custom task application
    syncWithCloud($progressBar->getPercentage())

    // Some other custom application
    sendToRaspberryPiDisplay($progressBar->getProgress(), $progressBar->getMaxProgress())
}

License

This library is licensed under the MIT License (MIT). See the LICENSE for more details.

nickbeen/php-cli-progress-bar 适用场景与选型建议

nickbeen/php-cli-progress-bar 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48.07k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 06 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「cli」 「progress bar」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nickbeen/php-cli-progress-bar 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nickbeen/php-cli-progress-bar 我们能提供哪些服务?
定制开发 / 二次开发

基于 nickbeen/php-cli-progress-bar 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 48.07k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 14
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-18