- 1,在TP6根目录下执行这条命令,他会生成一个文件夹目录下面包含Hello.php
php think make:command Hello hello
- 2 在这个文件里面写你的逻辑代码
class Hello extends Command
{
protected function configure()
{
// 指令配置
$this->setName('hello')
->setDescription('the hello command');
}
protected function execute(Input $input, Output $output)
{
// 指令输出
$output->writeln('每分钟添加一条数据就要开始了!');
$this->logic();//逻辑方法
$output->writeln('每分钟添加一条数据已经操作成功了!');
$time = $time = date("Y-m-d H:i:s");
$output->writeln("操作时间为: $time");
}
//逻辑代码
public function logic()
{
// echo '这里写你要实现的逻辑代码';
}
}
- 3 写完以后 去这个路径下面的文件写命令,方便执行
- 4 去宝塔上面找计划任务
- 5 点击执行
- 6 可查看日志