laravelapachecroncpanellaravel-scheduler

Laravel CPanel Cron Job command doesn't run


I am having an issue implementating a Cron Job for my Laravel application on a Apache/CPanel shared server. I have a task command that works fine whenever i run it from the command line and also works fine when called daily but it is not running on a "Once a day" schedule.

The Cron Job bellow works perfectly when called each minute only if the Laravel command is also called everyMinute() as shown:

Cron call

php -d register_argc_argv=On /home/path/domain.com/artisan schedule:run > /dev/null 2>&1

Server schedule * * * * *

Laravel command:

$schedule->command('alert:dailly')->everyMinute();

The problem is that the command that i really want to work is once a day, and that doesn't work. The same command that once worked fine each minutes its just not called when once a day, as follows:

Cron call

php -d register_argc_argv=On /home/path/domain.com/artisan schedule:run > /dev/null 2>&1

Server schedule 0 0 * * *

Laravel command:

$schedule->command('alert:dailly')->cron('0 0 * * * *');

or

$schedule->command('alert:dailly')->daily();

Is there anything wrong?

Thank you!


Solution

  • You don't need to change the server schedule on your daily call.

    There should be one artisan cron on your server like so:

    * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
    

    This cron will be called every 1 minute and when it does, Laravel will evaluate your scheduled tasks.

    Later on your code use the daily:

    $schedule->command('cmd-name:op')->daily();
    

    Daily will run the task every day at midnight.

    For other schedule frequencies check the docs