OpenSwoole\Timer::clear

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Timer::clear(int $timerId)\:\ bool

Parameters

timerId

The ID of the Timer to clear

Return

success

if success, it returns true

fail

if it fails false will be returned

Description

Clear a Timer by passing its ID. When creating a timer with tick or after it will return its timer ID, you can use this to clear/stop the timer from running.

Note: When using OpenSwoole\Timer::clear it can only be used to clear timers from the current process space.

Example

<?php

$count = 0;
function run($timerId, $param1, $param2) use(&$count)
{
    $count++;

    var_dump($count);

    if($count >= 10)
    {
        OpenSwoole\Timer->clear($timerId);
    }
}

OpenSwoole\Timer->tick(1000, "run",["param1", "param2"]);
Last updated on September 1, 2022