本文主要介绍命令启动定时任务的功能,按照CRMEB标准版的程序为大家详细的进行实现过程的介绍
- 首先创建安装Worker,执行composer require topthink/think-worker 安装
- 在config/console.php中定义指令 'timer' => \crmeb\command\Timer::class

- 对应图1中的路径创建自定义指令crmeb\command\Timer.php

-
configure方法只要配置指令的内容,文件定义了一个timer的命令,设置了一个status的参数以及两个(d:是否DAEMON方式启动,以及i:执行间隔)的选项。
-
init方法在执行命令的时候对参数进行初始化并组合数据,判断命令是启动还是停止,是否修改执行间隔,是否以守护进程方式启动

-
execute开始执行命令调用下方start方法
-
start方法开始执行定时执行的逻辑按照设置的间隔时间($this->interval)进行执行,默认2秒运行一次,调用系统中app\event.php文件下定时任务事件订阅类

-
在定时任务事件订阅类中完成对应系统方法的调用,即可实现定时任务功能
-
命令行执行命令 php think timer start --d
