简单用例:thinkcmf6.0-自定义think命令行使用workerman:定时任务

注:关于环境配置及workerman安装已提前安装好,初步简单实用,不喜勿喷哈哈

1.注册think命令行;

  命令行注册位置:ThinkCMF\app\command\Demo.php

  配置基础指令:

  

 

  

protected function configure()
    {
        // 指令配置
    //设置的指令名称 $this->setName('Demo')
        //额外的参数:name ->addArgument('name', Argument::OPTIONAL, "your name")
        //https://www.kancloud.cn/uuling/tp5-console/366137可查看tp指令文档 ->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
       //运行命令行时的简短描述 ->setDescription('the zhulei one command'); }

  封装要定时执行的代码(workerman使用见:http://doc3.workerman.net/1993516)

protected function execute(Input $input, Output $output)
    {
        $worker = new Worker();

        // 设置时区,避免运行结果与预期不一致
        date_default_timezone_set('PRC');

        $worker->onWorkerStart = function () {
            // 每分钟的第1秒执行.
            new Crontab('1 * * * * *', function(){
                $this->sendDingChatMsg("测试:这特喵的是一个Workerman定时器任务1号","JIMUU-OMS","123456");
                echo "确认到这步了";
            });
            new Crontab('2 * * * * *', function(){
                $this->sendDingChatMsg("测试:这特喵的是一个Workerman定时器任务2号","JIMUU-OMS","123456");
                echo "确认到这步了";
            });
        };

        Worker::runAll();
    }

 2.配置指令:

  thinkcmf指令配置地址为(没有就自行新建):ThinkCMF\data\config\console.php

  

3.cmd运行:php think查看自己封装的自定义命令行是否OK

 4.运行自己自定义的命令行;

  cmd:php think demo结果如下

 

 5.运行OK,钉钉消息已发出

 

posted @ 2021-05-23 11:39  PHP小骚年  阅读(693)  评论(0编辑  收藏  举报