Swoole\Timer::clear

Declaration

<?php
Swoole\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 Swoole\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)
    {
        Swoole\Timer->clear($timerId);
    }
}

Swoole\Timer->tick(1000, "run",["param1", "param2"]);