TP6在寶塔添加定時任務


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終端中運行代碼:

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM