首页 > 其他 > 详细

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

时间:2021-05-23 14:46:40      阅读:38      评论:0      收藏:0      [点我收藏+]

注:关于环境配置及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,钉钉消息已发出

技术分享图片

 

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

原文:https://www.cnblogs.com/zhuleiphper/p/14800758.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!