markuszeller/php-timer

简单的计时器类

v1.1.1 2020-10-19 18:52 UTC

This package is auto-updated.

Last update: 2024-09-20 04:08:02 UTC


README

简单的计时器类

PHP from Packagist Install with Composer)

初始化计时器

$timer = new Timer();

执行一些耗时操作并停止计时器。

$timer->stop();

假设计时器在执行耗时操作时耗时66.6秒。

以不同格式接收值

  • 带有2位小数的分数

    // 66.60
    echo $timer->getSecondsFractioned();
    
  • 四舍五入为整数

    // 67
    echo $timer->getSecondsRounded();  
    
  • 格式化为时间 hh:mm:ss

    // 00:01:06
    echo $timer->getTimeFormatted();
    
  • 格式化为毫秒

    // 5000.1788139343
    sleep(5);
    echo $timer->getMilliseconds();
    
  • 不同的输出

$timer->setTotal(100);
$timer->setDone(88);

// █████████████████░░░
// 20 chars are default
echo $timer->getProgressAsciiBar(), PHP_EOL;

//  88.00%
echo $timer->getProgressPercentage(), PHP_EOL;

// 88/100
echo $timer->getProgressDone(), PHP_EOL;
  • 您也可以定义自己的输出

    • %b - 进度条
    • %c - 数量
    • %p - 百分比

    %c %b %p 将打印
    567/1234 █████████░░░░░░░░░░ 45.95%