TP6 定时器操作方法

本文介绍了在ThinkPHP6(TP6)框架中如何使用Workerman进行定时任务的配置和操作,包括安装Workerman、创建Timer命令、实现定时器、注册命令、启动和关闭定时器的步骤。此外,还提及了在控制器、service层和模型层的代码添加,以及结合了先前的Redis封装。详细教程链接:https://blog.csdn.net/Y_001010/article/details/119986380?spm=1001.2014.3001.5502
摘要由CSDN通过智能技术生成

一、安装workman

1

composer require workerman/workerman

二、创建 Timer 命令

1

php think make:command Timers

三、实现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
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值