Laravel - Task Scheduling

强颜欢笑 提交于 2021-01-03 06:29:39

问题


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();
}

So basically 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 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?

Thank you, Patrick


回答1:


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.



来源:https://stackoverflow.com/questions/47813514/laravel-task-scheduling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!