Laravel - Task Scheduling

I'm using Laravel 5.4 on a local WAMP Server. I wanted to perform a Task Scheduling but I'm not sure if I really understood how this works.

I created a command cronEmail and in the handle() function added code where I would get an Email. In Kernel.php I added this:

protected $commands = [
    'App\Console\Commands\cronEmail'
];

...

protected function schedule(Schedule $schedule)
{
    $schedule->command('send:email')
             ->everyMinute();
}

I want to get an email every minute. But how do I start this? I tried entering:

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

or even

php C:\wamp64\www\seo-parser\artisan schedule:run >> /dev/null 2>&1

on my cmd prompt, but I always get:

The system cannot find the path specified.

If I enter php artisan schedule:run it will actually send an email, but only once.

Did I understand the whole concept wrong? How do I do this properly?

Upvotes: 3

Views: 1891

Answers (1)

jrenk
jrenk

Reputation: 1416

As stated in the official Laravel documentation you need to add the following line to your crontab.

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

You do this by typing "crontab -e" in the console. Paste the above line and replace the "/path-to-your-project" with the path to your project.

This results in a cronjob wich calls the "php artisan schedule:run" command every minute.

This requires you to run Linux though. If you need an alternative to crontab when running Windows you can start by reading here.

Upvotes: 2

Related Questions