3

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 2
    I suggest you go for the homestead. So you can try the code in Linux environment and you can follow all the documentation step. E.g Cron Job. Another advantage is most of the hosting is using Linux. – Shiro Dec 14 '17 at 13:20
  • Here is how I accomplished Laravel task scheduling (cron jobs) on WAMP (Windows) in a way that handles the fact that sometimes computers sleep: https://stackoverflow.com/a/64689809/470749 – Ryan Nov 05 '20 at 01:09

1 Answers1

2

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.

jrenk
  • 1,387
  • 3
  • 24
  • 46
  • 3
    On Windows (more relevant to the actual question) you can use Task Scheduler – RiggsFolly Dec 15 '17 at 11:01
  • 1
    Yes, but Task Scheduler has no console so where do I put that line of code? * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1 – Patrick Teixeira Felix Dec 15 '17 at 14:01
  • @PatrickTeixeiraFelix You could create a .bat file which calls `php artisan schedule:run` and add it to Task Scheduler like this: `schtasks /create /tn "MyTask" /sc minute /mo 1 /tr "MyTask.bat"` – jrenk Dec 15 '17 at 14:11