Workerman定时器的调用!!

定时器是个好东西 当时也是研究了写法研究半天 具体在这里链接

啥也不说了 上代码 TP5


namespace app\push\controller;
use think\Controller;
use Workerman\Lib\Timer;
use Workerman\Worker;

class RunController extends Controller
{
    /**
     * 构造函数
     * @access public
     */

    public function _initialize()
    {

        $worker             = new Worker();
        $worker->onWorkerStart = function () {
                $time_interval = 2.5;
                Timer::add($time_interval, array($this, 'test'));
            }
        };
        //运行所有Worker;
        Worker::runAll();
    }

    public function test()
    {
        echo "test run\n";
    }
}

你可能感兴趣的:(Thinkcmf)