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 點擊執行
或者 Linux設置crontab計划任務
//設置成每分鍾執行一次 1 * * * * php /www/wwwroot/項目名稱/think hello
6 可查看日志
在phpstorm終端中運行代碼: