Search code examples
phplaravel-5laravel-scheduler

Laravel 5.2 Scheduler


Dear Stackoverflowers,

I've created 2 Laravel commands, one that clears the db of records, an the other one that sends an email.

If I call them separately they work, and in the app/console/kernel.php file I have this:

protected function schedule(Schedule $schedule)
{
    // minute, hour, day of month, month, day of week
    // *, *, *, *, * elke minuut

    $schedule->command('item:removeChecked')->everyMinute();

    $schedule->command('email:sendList')->everyMinute();
}

So when I run the php artisan schedule:run command, it runs the 2 commands immediately and responds with the following:

Running scheduled command: '/usr/bin/php' 'artisan' item:removeChecked > '/dev/null' 2>&1 &
Running scheduled command: '/usr/bin/php' 'artisan' email:sendList > '/dev/null' 2>&1 &

But then it stops and does nothing.

So my question is how could I get this to work? I cant find any good documentation about this paret of Laravel, probably because it's quite new.

Thanks in advance for helping me.

Theo.


Solution

  • You have to add an cron job.

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

    https://laravel.com/docs/5.2/scheduling#introduction

    Rémon