EasySwoole 定时器(下)毫秒定时器的使用

EasySwoole版本:3.3.4
引入Timer类
注册事件,在其内运行毫秒定时器

use EasySwoole\Component\Timer;

public static function mainServerCreate(EventRegister $register)
    {
        //使用毫秒定时器
        $testParam = "Test Timer \n";
        $register->add(EventRegister::onWorkerStart, function (\swoole_server $server, $workerId) use ($testParam) {
            //选择一个进程来执行定时器任务
            if ($workerId == 0) {
                // 每隔100毫秒执行一次
                Timer::getInstance()->loop(100, function () use ($testParam) {
                    echo $testParam;
                });
                // todo

            }
        });
    }

发布了103 篇原创文章 · 获赞 81 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/yuhezheg/article/details/104132582
今日推荐