Laravel scheduler is not running automatically

2019-06-04 14:02发布

问题:

I have made a scheduler. When I call it with php artisan userRanking it works.

This is the code in Kernel.php:

protected $commands = [
    \App\Console\Commands\UserRanking::class,
];

protected function schedule(Schedule $schedule)
{
    $schedule->command('userRanking')
             ->everyMinute();
}

How do I dispatch it so that it runs automatically?

回答1:

You have to set up a single cron job that calls the schedule runner every minute:

* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1

Read Laravel's Scheduler docs for more info.