承接 davidbehler/timer 相关项目开发

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

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

davidbehler/timer

Composer 安装命令:

composer require davidbehler/timer

包简介

A timer, in PHP. You can (re)start, pause and stop. And get the passed time. You can start/control multiple timers simultaneously by label.

README 文档

README

A timer, in PHP. You can (re)start, pause and stop. And get the passed time. With TimerCollection you can run multiple timers at once.

Currently supported time measuring options:

  • Timer::DATETIME_TYPE: uses PHP's DateTime class (this is the default)
  • Timer::MICROTIME_TYPE: uses PHP's microtime function

Installation

Using Composer

composer require davidbehler/timer

Without Composer

You can also download it from [Github] (https://github.com/davidbehler/timer), but no autoloader is provided so you'll need to register it with your own PSR-4 compatible autoloader.

Timer Usage

Create a new timer with autostart

use DavidBehler\Timer\Timer;

$timer = new Timer;

Create a new timer with autostart and microtime option

$timer = new Timer(true, Timer::MICROTIME_TYPE);

Create a new timer without autostart

$timer = new Timer(false);

Manually start a timer

$timer = new Timer(false);

$timer->start();

Pause a timer

$timer = new Timer;

$timer->pause();

Stop a timer

$timer = new Timer;

$timer->stop();

Unpause a paused timer

$timer = new Timer;

$timer->pause();
$timer->start();

Restart a timer

$timer = new Timer;

$timer->restart();

Get duration of running timer in microseconds (uses current time)

$timer = new Timer;

usleep(1000);

$timer->getDuration(); // returns 0.001 (in a perfect world, but of course timings aren't this perfect)

Get duration of running timer in seconds with 4 digits after decimal point (uses current time)

$timer = new Timer;

usleep(555);

$timer->getDuration(true, 5); // returns 0.00055 (in a perfect world, but of course timings aren't this perfect)

Get duration of paused timer in seconds

$timer = new Timer;

usleep(500);

$timer->pause();

usleep(500);

$timer->getDuration(); // returns 0.0005 (in a perfect world, but of course timings aren't this perfect)

Get duration of stopped timer in seconds

$timer = new Timer;

usleep(500);

$timer->stop();

usleep(500);

$timer->getDuration(); // returns 0.0005 (in a perfect world, but of course timings aren't this perfect)

Get duration of timer paused/started multiple times in seconds

$timer = new Timer;

sleep(1);

$timer->pause();

usleep(500);

$timer->start();

sleep(2);

$timer->pause();

$timer->getDuration(); // returns 3.005 (in a perfect world, but of course timings aren't this perfect)

Get a report

$timer->getReport();

TimerCollection Usage

Create a new TimerCollection with the microtime option. All timers within this collection will use the measuring option the collection was inititialized with.

use DavidBehler\Timer\TimerCollection;

$timerCollection = new TimerCollection(Timer::MICROTIME_TYPE);

Start a time and get it's duration in seconds

$timerCollection->start('timer 1');

$timerCollection->getDuration('timer 1');

Start multiple timers at once and get their durations

$timerCollection->start('timer 1');
$timerCollection->start('timer 2');

$timerCollection->getDuration('timer 1');
$timerCollection->getDuration('timer 2');
// or
$timerCollection->start(array('timer 1', 'timer 2'));
$timerCollcetion->getDurations(array('timer 1', 'timer 2')); // returns an array of durations with timer labels as indeces

You can also stop, pause and restart multiple timers at once

$timerCollection->stop(array('timer 1', 'timer 2'));
$timerCollection->pause(array('timer 1', 'timer 2'));
$timerCollection->restart(array('timer 1', 'timer 2'));

You can get a list of all timers

$timerCollection->getTimers(); // returns an array with all setup timers
$timerCollection->getTimers(true); // returns an array with all the setup timers' labels

Get a single timer's report

$timerCollection->getReport('timer 4');

Get a report for multiple timers

$timerCollection->getReports(array('timer 5', 'timer 6'));

统计信息

  • 总下载量: 277
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-03-09

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固