手机直播源码,每日定时刷新用户任务

手机直播源码,每日定时刷新用户任务实现的相关代码

 

<?php
namespace app\common\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
 
class Task extends Command
{
    protected function configure()
    {
        //设置名称为task
        $this->setName('task')
            //增加一个命令参数
            ->addArgument('action', Argument::OPTIONAL, "action")
            ->addArgument('force', Argument::OPTIONAL, "force");
    }
    protected function execute(Input $input, Output $output)
    {
        //获取输入参数
        $action = trim($input->getArgument('action'));
        $force = trim($input->getArgument('force'));
        // 配置任务
        $task = new \EasyTask\Task();
        $task->setRunTimePath('./runtime/');
        $task->setDaemon(true);
        $task->addFunc(function () {
           $this->monitor();
        }, 'request', 100, 1);
        // 根据命令执行 每隔100s执行一次monitor函数,只开启一个进程
        if ($action == 'start')
        {
            $task->start();
        }
        elseif ($action == 'status')
        {
            $task->status();
        }
        elseif ($action == 'stop')
        {
            $force = ($force == 'force'); //是否强制停止
            $task->stop($force);
        }
        else
        {
            exit('Command is not exist');
        }
    }
    protected function monitor()
    {
            ///执行相应的函数代码 和正常的函数一样 操作数据库什么的
    }
}

 

然后直接执行代码即可

 


开始:
php think task start 
 
查看状态:
php think task status
 
结束
php think task stop

 

以上就是手机直播源码,每日定时刷新用户任务实现的相关代码, 更多内容欢迎关注之后的文章

 

posted @ 2022-03-30 14:11  云豹科技-苏凌霄  阅读(80)  评论(0)    收藏  举报