Swoole\Timer::after
(PECL swoole >= 1.9.0)
Execute a function after a specified time
Description
Creates a one-shot timer, which is destroyed once its callback has run. Unlike sleep(), it does not block the current process.
Parameters
msThe delay in milliseconds. Must be greater than or equal to
1; a lower value emits anE_WARNINGand the call fails.callbackThe function to execute once the delay has elapsed. It is called as
callback(mixed ...$params). UnlikeSwoole\Timer::tick, the timer ID is not passed to the callback.paramsAdditional values passed to
callback.
Return Values
Returns the timer ID, which can be passed to Swoole\Timer::clear to cancel the timer before it fires. Returns false if the timer could not be created, in particular when ms is less than 1.
Examples
Swoole\Timer::after() example
<?php
Swoole\Timer::after(1000, function (string $name) {
echo "Hello, $name\n";
}, "Swoole");
?>The above example will output:
Hello, Swoole