php think make:command PullAppFile
<?php
declare (strict_types = 1);
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\facade\Db;
/**
*
* @author Administrator
*
*/
class PullAppFile extends Command
{
protected function configure()
{
// 指令配置
$this->setName('pullappfile')
->setDescription('the pullappfile command');
}
protected function execute(Input $input, Output $output)
{
// 任务开始
$output->writeln('Begin task');
//处理任务
$this->handleTask();
// 任务结束
$output->writeln('End task');
}
protected function handleTask(){
Db::table('bq_ceshi')->insert(['name'=>time()]);
}
}
<?php
// +----------------------------------------------------------------------
// | 控制台配置
// +----------------------------------------------------------------------
return [
// 指令定义
'commands' => [
'pullappfile' => 'app\command\PullAppFile',
],
];
执行指令:php think pullappfile
宝塔定时任务: