An open API service indexing awesome lists of open source software.

https://github.com/ayesh/php-timer

A stop-watch and timer with start/stop/pause features and minimal human-friendly formatting.
https://github.com/ayesh/php-timer

php php-timer timer

Last synced: 9 months ago
JSON representation

A stop-watch and timer with start/stop/pause features and minimal human-friendly formatting.

Awesome Lists containing this project

README

          

# PHP Timer

[![Latest Stable Version](https://poser.pugx.org/ayesh/php-timer/v/stable)](https://packagist.org/packages/ayesh/php-timer) [![License](https://poser.pugx.org/ayesh/php-timer/license)](https://packagist.org/packages/ayesh/php-timer) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Ayesh/php-timer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Ayesh/php-timer/?branch=master) [![CI](https://github.com/Ayesh/php-timer/workflows/CI/badge.svg)](https://github.com/Ayesh/php-timer/actions) [![codecov](https://codecov.io/gh/Ayesh/php-timer/branch/master/graph/badge.svg)](https://codecov.io/gh/Ayesh/php-timer) [![Too many badges](https://img.shields.io/badge/style-too_many-brightgreen.svg?style=toomany&label=badges)](https://github.com/Ayesh/php-timer)

## Synopsis
A helper class to calculate how long a particular task took.

This class is similar to phpunit/php-timer, but not a fork, nor mimic its functionality.

- Multiple timers by a given key.
- Read the current time elapsed without stopping the timer.
- Stop the timer, and continue from where it left (stopwatch).
- Dead simple API with only 4 static methods.
- 100% unit test coverage.
- Gets you precise time in milliseconds (with options to convert to seconds)
- Individual `Stopwatch` class for serialization and other use cases.

## Prerequisites

- PHP 8.2 or later.

## Installing

The simplest way would be to install using [composer](https://getcomposer.org).

```bash
composer require ayesh/php-timer
```

## Usage

It is pretty simple to use the timer, with all methods being static, and allowing only 4 methods.

#### Start timer
```php
";
echo Timer::read('laps', Timer::FORMAT_SECONDS); // 2 seconds (1 + 1)
````

## Development and tests

All issues are PRs are welcome. Travis CI and PHPUnit tests are included. If you are adding new features, please make sure to add the test coverage.

## Credits
By [Ayesh Karunaratne](https://aye.sh) and [contributors](https://github.com/Ayesh/php-timer/graphs/contributors).

kthxbye