laravel的调度任务

xiaoxiao2021-02-28  47

首先创建调度任务:php artisan make:command AutoRefund

编辑 app/Console/Commands/AutoRefund.php文件,修改如下几处:

/**     * The name and signature of the console command.     *     * @var string     */    protected $signature = 'autorefund';  //任务调度名称    /**     * The console command description.     *     * @var string     */    protected $description = 'Command description'; //描述 没有用    /**     * Create a new command instance.     *     * @return void     */    public function __construct()    {        parent::__construct();    }    /**     * Execute the console command.     *     * @return mixed     */    public function handle()

    {

           // 功能代码

     }

  

编辑 app/Console/Kernel.php文件:

 /**     * The Artisan commands provided by your application.     *     * @var array     */    protected $commands = [     \App\Console\Commands\AutoRefund::class,            ];    /**     * Define the application's command schedule.     *     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule     * @return void     */    protected function schedule(Schedule $schedule)    {        $schedule->command('autorefund')            ->timezone('Asia/Shanghai')            ->everyMinute();    } 

然后crontab -e编辑定时任务:

* * * * *  /usr/local/php/bin/php /var/www/xxxlaravel/artisan schedule:run >> /dev/null 2>&1

转载请注明原文地址: https://www.6miu.com/read-2630939.html

最新回复(0)