一、安装workman
1 |
|
二、创建 Timer 命令
1 |
|
三、实现Timer
<?php declare (strict_types = 1); namespace app\API\command; use app\API\service\Order; use app\controller\Index; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; use Workerman\Worker; class Timers extends Command { protected $timer; protected $interval =2; protected function configure() { // 指令配置 $this->setName('timer') ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections') ->addOption('d', null, Option::VALUE_NONE, 'daemon(守护进程)方式启动') ->addOption('i', null, Option::VALUE_OPTIONAL, '多长时间执行一次') ->setDescription('开启/关闭/重启 定时任务'); } protected function init(Input $input, Output $output) { global $ar