PHPackages                             davidbehler/timer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. davidbehler/timer

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

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.

v2.0.0(7y ago)0277MITPHPPHP &gt;=7.1

Since Mar 9Pushed 7y agoCompare

[ Source](https://github.com/davidbehler/timer)[ Packagist](https://packagist.org/packages/davidbehler/timer)[ Docs](https://github.com/davidbehler/timer/)[ RSS](/packages/davidbehler-timer/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)DependenciesVersions (6)Used By (0)

timer
=====

[](#timer)

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
------------

[](#installation)

Using Composer

```
composer require davidbehler/timer
```

Without Composer

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

Timer Usage
-----------

[](#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
---------------------

[](#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'));
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

2622d ago

Major Versions

v1.2.0 → v2.0.02019-03-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/a44653c525ce0efa516c13949f0483e7fbbdc152c3418e64c8202ae5ee9c824b?d=identicon)[davidbehler](/maintainers/davidbehler)

---

Top Contributors

[![davidbehler](https://avatars.githubusercontent.com/u/96450?v=4)](https://github.com/davidbehler "davidbehler (12 commits)")

---

Tags

performancetimetimerreportbenchmarkstatisticsdurationstopwatchtimers

### Embed Badge

![Health badge](/badges/davidbehler-timer/health.svg)

```
[![Health](https://phpackages.com/badges/davidbehler-timer/health.svg)](https://phpackages.com/packages/davidbehler-timer)
```

###  Alternatives

[brick/date-time

Date and time library

3623.3M61](/packages/brick-date-time)[ayesh/php-timer

High-resolution and monotonic stop-watch for all your needs. Supports timer start, pause, resume, stop, read, and minimal conversion.

22226.4k11](/packages/ayesh-php-timer)[jsanc623/phpbenchtime

A lightweight benchmark timer and lap profiler for PHP.

2539.1k1](/packages/jsanc623-phpbenchtime)[aspose-cloud/aspose-words-cloud

Open, generate, edit, split, merge, compare and convert Word documents. Integrate Cloud API into your solutions to manipulate documents. Convert PDF to Word (DOC, DOCX, ODT, RTF and HTML) and in the opposite direction.

32157.4k](/packages/aspose-cloud-aspose-words-cloud)[dragon-code/benchmark

Simple comparison of code execution speed between different options

11934.7k5](/packages/dragon-code-benchmark)[scheb/tombstone-analyzer

Generates reports based on the logs from scheb/tombstone-logger

28378.1k2](/packages/scheb-tombstone-analyzer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
