首页 > 解决方案 > Php artisan schedule dosen't execute the command

问题描述

so I'am trying to run a task with laravel schedule and php schedule:run works well but it does not execute the command in real

There is my kernel class

use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        //

    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        //$schedule->exec('php artisan migrate:fresh')->everyMinute();
        $schedule->command('migrate:fresh')->everyMinute();
    }
}

And the result of php schedule:run

Running scheduled command: '/usr/bin/php7.2' artisan migrate:fresh > '/dev/null' 2>&1

标签: phplaravel

解决方案


您需要创建一个 CRON 作业以每分钟运行一次调度程序。

然后,CRON 将每分钟自动触发并运行您在 kernel->schedule 函数中设置的任何命令。

你可以在Laravel 文档的启动调度程序下找到详细信息


推荐阅读