1. 执行命令,生成自定义命令
php think make:command Custom
<?php
declare (strict_types = 1);namespace app\command;use app\facade\AdmUser;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use think\console\Output;class Custom extends Command
{protected function configure(){// 指令配置,设置设置参数$this->setName('custom')->setDescription('the custom command');}protected function execute(Input $input, Output $output){// 这里写对于的逻辑AdmUser::clearRoom();$output->writeln('清除成功');}}
2. 配置文件console.php
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [// 指令定义'commands' => ['custom' => app\command\Custom::class,],
];
3. 设置shell脚本定时任务
如何你的服务器有多个php版本,默认版本不是该程序版本 需要具体指定如下:
cd /www/wwwroot/his4.dieya.net && /www/server/php/74/bin/php think custom