unregister_tick_function

(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)

unregister_tick_function各 tick の実行用の関数の登録を解除する

説明

unregister_tick_function(callable $callback): void

callback という名前の関数の登録を解除します。 これにより、tick がコールされた 場合でもこの関数は実行されなくなります。

パラメータ

callback

登録を解除する関数

戻り値

値を返しません。

参考

add a note add a note

User Contributed Notes 3 notes

up
4
ElectricHeart at ya dot ru
8 years ago
You can unregister closure-function:

declare(ticks = 1000);
$startTime = microtime(true);
$tick = true;
$closure = function () use ($startTime, &$tick) {
    if (((microtime(true) - $startTime) > 5) && $tick) {
        $tick = false;
        throw new \Exception('Time to run code left');
    }
};

try {
            register_tick_function($closure);
            //do your code
            $result = 1;
            return $result;
        } catch (\Exception $e) {
            throw $e;
        } finally {
            unregister_tick_function($closure);
}
up
1
Greg
12 years ago
It's not so clear, but, at least as of PHP 5.3.13, you cannot use this inside of the handler itself as it will throw an error:

<?php

declare(ticks=2);

function
tick_handler()
{
   
unregister_tick_function('tick_handler');
}

register_tick_function('tick_handler');

set_time_limit(0);
usleep(500000);

?>

results in:

warning: unregister_tick_function(): Unable to delete tick function executed at the moment in [filename]

So if you want to unregister it must be done outside of the handler.
up
-3
rob dot eyre at gmail dot com
13 years ago
Note that unregister_tick_function() can also accept a callback in the form of an array (either static, like array($className, $methodName) or instance, like array(&$this, $methodName)).

It cannot accept an anonymous function, however.
To Top