thinkphp6 定时任务
2022-11-24 11:10:29
208
{{single.collect_count}}

使用命令行形式实现定时任务
一、创建一个自定义命令类文件

php think make:command Hello hello

会生成一个app\command\Hello命令行指令类,我们修改内容如下:

<?phpdeclare (strict_types = 1);namespace app\command;use think\console\Command;use think\console\Input;use think\console\input\Argument;use think\console\input\Option;use think\console\Output;class Hello extends Command{protected function configure(){// 指令配置$this->setName('hello')->setDescription('Say Hello');}protected function execute(Input $input, Output $output){// 指令输出$output->write('hello world');}}

二、配置config/console.php文件

<?phpreturn ['commands' => ['hello' => 'app\command\Hello',]];

三、运行hello命令

php think hello

输出

hello world

书写脚本文件
每一小时运行

* */1 * * * /etc/php think hello
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}