简体   繁体   English

Cron Job无法在共享主机上的Godaddy上的Laravel项目中工作

[英]Cron Job not working in Laravel project on Godaddy on shared hosting

I am trying to setup a Cron job which will run after every minute and perform some task. 我正在尝试设置Cron作业,该作业每分钟运行一次并执行一些任务。 I am using Laravel 5.5 and my site is hosted on Godaddy with shared hosting plan. 我正在使用Laravel 5.5,并且我的网站通过共享托管计划托管在Godaddy上。 First I have implemented schedule method in app/Console/Kernel.php file like below: 首先,我已经在app / Console / Kernel.php文件中实现了schedule方法,如下所示:

    protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        $video = new Video;
        $video->title = 'sample title';
        $video->save();
    })->everyMinute();
}

Then I have created a Cron Job in relevant section from Godaddy cPanel section. 然后,在Godaddy cPanel部分的相关部分中创建了Cron Job。 This section looks like below: 本节如下所示:

在此处输入图片说明

I have also setup to send me email every time this tasks runs but nothing is happening. 我还设置了每次运行此任务但没有任何反应时向我发送电子邮件。 No email, no new entry in Videos table. 没有电子邮件,在“视频”表中没有新条目。 Although other parts of application are configured correctly and working fine. 尽管应用程序的其他部分已正确配置并且可以正常工作。 As far as my guess is, there seems to be something wrong with the path to artisan file that is given in php command. 据我的猜测,php命令中指向artisan文件的路径似乎有问题。 I have tried different combinations but no luck. 我尝试了不同的组合,但没有运气。

I have fixed the issue. 我已经解决了这个问题。 The problem was in the command. 问题出在命令中。 Firstly I had to put ~ at the start of the path to artisan file. 首先,我必须将〜放在工匠档案路径的开头。 Second I had to enter the absolute path to the php executable. 其次,我必须输入php可执行文件的绝对路径。 So the final command that worked for me is: 因此,对我有用的最终命令是:

/usr/local/bin/php ~/public_html/fifa/artisan schedule:run >> /dev/null 2>&1

I am using Laravel Forge and this works for me: 我正在使用Laravel Forge,这对我有用:

php /home/forge/project_directory/artisan schedule:run

Is /public_html/fifa the path to your project? / public_html / fifa是您项目的路径吗? Try running artisan directly from your project directory: 尝试直接从您的项目目录运行artisan:

php /path_to_project/artisan schedule:run

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM