swoole定时器

linux中的计划任务,最小的单位只能到分钟级别,如有业务在秒级单位的计划,crontab将无法完成。而
swoole_timer是基于timerfd+epoll实现的异步毫秒定时器,为我们实际提示了很好的解决方案。

一次性定时器

<?php
// 5秒后输出 hello world
swoole_timer_after(3*1000,function (){
echo "hello world
";
});

效果:

 周期性定时器

<?php
// 每隔3秒输出 hello world
swoole_timer_tick(3*1000,function (){
echo "hello world
";
});
原文地址:https://www.cnblogs.com/qiguaideta/p/11548851.html