注:關於環境配置及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,釘釘消息已發出