0
votes

I am trying to setup a Cron job which will run after every minute and perform some task. I am using Laravel 5.5 and my site is hosted on Godaddy with shared hosting plan. First I have implemented schedule method in app/Console/Kernel.php file like below:

    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. This section looks like below:

enter image description here

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. I have tried different combinations but no luck.

2
have you ssh access to your hosting plan ? if yes, try to copypast your command and se if is working - if no, try to check by phpinfo() if your path looks good.Yanis-git
There was some problem with the path. ( php ~/public_html/fifa/artisan schedule:run >> /dev/null 2>&1 ) worked on ssh and the task put the record in DB but still Cron not working.Khawar Raza
I have no experience with GoDaddy, but as you know, schedule:run is a long running process. If you quit the ssh session, so does the process stop. Workarounds depend on your hosting service. Have a look at their knowledgebase for long running processes in PHP. I may have a universal trick, but for that you have to make sure the PHP command shell_exec() is accepted by the server. Just try it out in tinker shell_exec('ls -la') and see if you get a list of files or an error.Dimitri Mostrey

2 Answers

2
votes

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. So the final command that worked for me is:

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

I am using Laravel Forge and this works for me:

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

Is /public_html/fifa the path to your project? Try running artisan directly from your project directory:

php /path_to_project/artisan schedule:run