使用tp6内置console+linux crontab实现定时任务
编写脚本文件开头要加 #!/bin/bash
console代码示例
<?php
#!/bin/bash
/*
* author hzbskak
* email hzbskak@gmail.com
* date 2021/4/12
*/
namespace xxx\command\crontab;
use PhpAmqpLib\Exchange\AMQPExchangeType;
use PhpAmqpLib\Message\AMQPMessage;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;
/**
* 定时任务跑xxx队列
* Class RenewOrder
* @package manydads\command\crontab
*/
class xxx extends Command
{
protected function configure()
{
// 指令配置
$this->setName( 'reneworder')
->setDescription( '定时任务跑续费订单队列');
}
/**
*
* @param Input $input
* @param Output $output
* @return int|void|null
*/
protected function execute(Input $input, Output $output)
{
// todo
exit;
}
}
console.php配置文件
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
'test:xxx' => "xxx\\command\\xxx\\xxx",// xxx
],
];
linux cli执行:
先用命令 php think 查看是否有 test:xxx 命令
执行队列:php think test:xxx

本文介绍如何使用ThinkPHP 6的内置控制台结合Linux crontab实现定时任务。通过示例代码展示了创建自定义命令类的方法,并配置了控制台来执行特定任务。
236

被折叠的 条评论
为什么被折叠?



