PHPackages                             neutron/tip-top - 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. neutron/tip-top

ActiveLibrary

neutron/tip-top
===============

Tip-Top, a library to set timeouts and periodic timers

0.2.0(12y ago)91021MITPHPPHP &gt;=5.3.3

Since May 12Pushed 12y ago1 watchersCompare

[ Source](https://github.com/romainneutron/Tip-Top)[ Packagist](https://packagist.org/packages/neutron/tip-top)[ RSS](/packages/neutron-tip-top/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

\#TIP-TOP

[![Build Status](https://camo.githubusercontent.com/474a2c7d660601bd868f9ea63483d3d977224c0ca8b110d733e103d74e8cc6f4/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f726f6d61696e6e657574726f6e2f5469702d546f702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/romainneutron/Tip-Top)

A micro library to set timeouts and periodic timers.

```
$clock = new Clock();
// triggers a callback every second
$timer = $clock->addPeriodicTimer(1, function ($timer) {
    echo "BOOM ! I'm triggered every second !\n";
});
```

It uses [Evenement](https://github.com/igorw/evenement). Most of the timers code has been taken from [ReactPHP](https://github.com/reactphp/react) timers implementation.

[![Tip-Top !](https://camo.githubusercontent.com/bcb35aa88279aa8d7d68783c3ee999df0800298b8df0a17f843fa94b1e05ed16/68747470733a2f2f7261772e6769746875622e636f6d2f726f6d61696e6e657574726f6e2f5469702d546f702f6d61737465722f646f63732f736f757263652f5f7468656d65732f416c6368656d792f7374617469632f696d672f70726f6a6563742e706e67)](https://tip-top.readthedocs.org)

Installation
------------

[](#installation)

The recommended way to use tip-top is [through composer](http://getcomposer.org).

```
{
    "require": {
        "neutron/tip-top": "0.2.*"
    }
}
```

Disclaimer
----------

[](#disclaimer)

### Limitations

[](#limitations)

- Tip-Top requires you declare ticks in the script you're running.

```
declare(ticks=1);

```

- Tip-Top may not work as expected with blocking calls (try it before)

### Is this blocking or non-blocking IO ?

[](#is-this-blocking-or-non-blocking-io-)

TipTop is non blocking, but it has been designed to support some blocking calls. Timers and timeout may be triggered lately in case you use blocking calls like `sleep(5)`.

A common workaround for `sleep` is to iterate 1 seconds sleeps : `for ($i=0; $i!=5; $i++;) {sleep(1);}`.

### Has the clock atomic precision ?

[](#has-the-clock-atomic-precision-)

Unfortunately, this library is based on a hack on the [pcntl\_alarm](php.net/manual/en/function.pcntl-alarm.php) function. Therefore, the resolution of the clock is the second, and it has shift that is approximatively 0,001 second per second.

### What's the use case for such clock ?

[](#whats-the-use-case-for-such-clock-)

Think about long running processes that have to be checked regularly.

Documentation
-------------

[](#documentation)

[API browser](https://tip-top.readthedocs.org/en/latest/_static/API/).

### Examples

[](#examples)

There are two main methods on the `Neutron\TipTop\Clock` object : `addPeriodicTimer` and `addTimer`.

```
use Neutron\TipTop\Clock;

// mandatory for the clock to work
declare(ticks=1);

$clock = new Clock();

// triggers a callback every second
$timer = $clock->addPeriodicTimer(1, function ($timer) {
    echo "BOOM ! I'm triggered every second !\n";
});

// triggers a callback in 5 second
$timer = $clock->addTimer(5, function ($timer) {
    echo "BOOM ! I was planned 5 seconds ago !\n";
});

// removes all timers
$clock->clear();
```

### Remove a timer

[](#remove-a-timer)

You can remove a timer using its `cancel` method :

```
use Neutron\TipTop\Clock;

// mandatory for the clock to work
declare(ticks=1);

$clock = new Clock();

$timer = $clock->addPeriodicTimer(1, function ($timer) {
    if ($stop) {
        $timer->cancel();
    }
});
```

### Clear all timers

[](#clear-all-timers)

You may want to clear all timers :

```
use Neutron\TipTop\Clock;

// mandatory for the clock to work
declare(ticks=1);

$clock = new Clock();

$timer = $clock->addPeriodicTimer(1, function ($timer) { echo "Hello"; });
$timer = $clock->addPeriodicTimer(1, function ($timer) { echo "Hello World"; });

// removes all timers
$clock->clear();
```

### Block

[](#block)

You can sometimes want to block until all timers have finished, use the `block`method to do that.

```
use Neutron\TipTop\Clock;

// mandatory for the clock to work
declare(ticks=1);

$clock = new Clock();

// echoes three times
$clock->addPeriodicTimer(1, function (signature) {
    echo "The block method blocks \n";
}, 3);

$clock->block();
echo "This line will be blocked until last timer executes
```

### Tests

[](#tests)

Tip Top is functional and unit testable with PHPUnit. To run tests on your system, please be sure to install dev-dependencies with `composer install --dev`, then run either `bin/phpunit -c phpunit.xml.dist` for unit tests, either `bin/phpunit -c phpunit-functional.xml.dist` for functional tests.

\##License

This project is licensed under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

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 ~13 days

Total

4

Last Release

4713d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3c264f69af4c60cb9cc98a522b4663f4b6a2708629cabc14409478ab6fc35348?d=identicon)[romain](/maintainers/romain)

---

Top Contributors

[![romainneutron](https://avatars.githubusercontent.com/u/137574?v=4)](https://github.com/romainneutron "romainneutron (49 commits)")

---

Tags

timertimeoutperiodperiodic

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/neutron-tip-top/health.svg)

```
[![Health](https://phpackages.com/badges/neutron-tip-top/health.svg)](https://phpackages.com/packages/neutron-tip-top)
```

###  Alternatives

[phpunit/php-timer

Utility class for timing

7.7k876.7M130](/packages/phpunit-php-timer)[react/promise-timer

A trivial implementation of timeouts for Promises, built on top of ReactPHP.

34141.9M96](/packages/react-promise-timer)[spatie/period

Complex period comparisons

1.7k4.0M10](/packages/spatie-period)[hhxsv5/laravel-s

🚀 LaravelS is an out-of-the-box adapter between Laravel/Lumen and Swoole.

3.9k676.0k10](/packages/hhxsv5-laravel-s)[league/period

Time range API for PHP

7335.4M21](/packages/league-period)[jbzoo/utils

Collection of PHP functions, mini classes and snippets for everyday developer's routine life.

8321.5M36](/packages/jbzoo-utils)

PHPackages © 2026

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