在 cPanel 中设置 Laravel cron 作业
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/44854161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up a Laravel cron job in cPanel
提问by Johnny
I have the following function:
我有以下功能:
protected function schedule(Schedule $schedule)
{
$schedule->command('email:users')->everyMinute();
}
when I run the command
当我运行命令时
artisan schedule:run
it sends an email but when I add the following command to the cpanel as a cron job it doesn't send any email. Cpanel suppose to email me a notification when the cron job is run but I haven't receive a single email.
它会发送一封电子邮件,但是当我将以下命令作为 cron 作业添加到 cpanel 时,它不会发送任何电子邮件。Cpanel 假设在运行 cron 作业时通过电子邮件向我发送通知,但我没有收到一封电子邮件。
php /home/rain/artisan schedule:run 1>> /dev/null 2>&1
php /home/rain/artisan schedule:run 1>> /dev/null 2>&1
Where am I doing wrong?
我哪里做错了?
Also when I run the command artisan schedule:run
it runs it only once. I am very curious why do I have to add ->everyMinute();
if it is not going to run every minute? If I want to send it weekly I can setup the cron job. Why do I have to write to add ->weekly();
in the function if cron job is sending it weekly?
此外,当我运行命令时,artisan schedule:run
它只运行一次。我很好奇,->everyMinute();
如果不是每分钟运行一次,为什么我必须添加?如果我想每周发送一次,我可以设置 cron 作业。->weekly();
如果 cron 作业每周发送一次,为什么我必须编写以添加该函数?
采纳答案by Pascal Meunier
The Laravel scheduler assumes you have a cronjob every minutes. The scheduler is only useful if you want to have multiple tasks.
Laravel 调度程序假设您每分钟都有一个 cronjob。调度程序仅在您想拥有多个任务时才有用。
Normally you have one single cronjob configured in cPanel and you can set the scheduler to everyWeek()
and have another task that would be everyDay()
without having to add of change the cronjobs in your cPanel.
通常,您在 cPanel 中配置了一个单一的 cronjob,您可以将调度程序设置为everyWeek()
另一个任务,而everyDay()
无需在您的 cPanel 中添加或更改 cronjob。
Laravel will automagically know if the task has already been run.
Laravel 会自动知道任务是否已经运行。
https://laravel.com/docs/5.4/scheduling
https://laravel.com/docs/5.4/scheduling
This Cron will call the Laravel command scheduler every minute. When the schedule:run command is executed, Laravel will evaluate your scheduled tasks and runs the tasks that are due.
这个 Cron 每分钟都会调用 Laravel 命令调度程序。当 schedule:run 命令被执行时,Laravel 会评估你的计划任务并运行到期的任务。