Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 794
Patrick Teixeira Felix Avatar asked Dec 20 '25 22:12

Patrick Teixeira Felix


1 Answers

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.

like image 175
jrenk Avatar answered Dec 22 '25 11:12

jrenk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!