swoole_timer_after

在指定的时间后执行函数,需要swoole-1.7.7以上版本。

swoole_timer_after(int $after_time_ms, mixed $callback_function);

swoole_timer_after函数是一个一次性定时器,执行完成后就会销毁。此函数与PHP标准库提供的sleep函数不同,after是非阻塞的。而sleep调用后会导致当前的进程进入阻塞,将无法处理新的请求。

$after_time_ms 最大不得超过 86400000

使用示例

swoole_timer_after(1000, function(){
    echo "timeout\n";
});