在cPanel中设置Laravel cron作业 [英] Setting up a Laravel cron job in cPanel

查看:56
本文介绍了在cPanel中设置Laravel cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下功能:

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

当我运行命令

artisan schedule:run 

它发送电子邮件,但是当我将以下命令作为cron作业添加到cpanel时,它不发送任何电子邮件.Cpanel希望在执行cron作业时向我发送通知,但我没有收到一封电子邮件.

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.

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

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

我在哪里做错了?

另外,当我运行命令 artisan schedule:run 时,它只运行一次.我很好奇,如果不能每分钟运行一次,为什么必须添加-> everyMinute(); ?如果我想每周发送一次,则可以设置Cron作业.如果cron作业每周发送一次,为什么我必须编写在函数中添加-> weekly(); ?

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?

推荐答案

Laravel调度程序假定您每分钟都有一次cronjob.仅当您要执行多个任务时,调度程序才有用.

The Laravel scheduler assumes you have a cronjob every minutes. The scheduler is only useful if you want to have multiple tasks.

通常,您在cPanel中配置了一个cronjob,您可以将调度程序设置为 everyWeek(),而不必执行添加其他任务即可成为 everyDay()在您的cPanel中更改cronjobs.

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.

Laravel将自动知道任务是否已经运行.

Laravel will automagically know if the task has already been run.

https://laravel.com/docs/5.4/scheduling

此Cron将每分钟调用一次Laravel命令调度程序.什么时候执行schedule:run命令,Laravel将评估您的安排任务并运行到期的任务.

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.

这篇关于在cPanel中设置Laravel cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆