使用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