skip to Main Content

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!

2

Answers


  1. I had a similar issue and never found out the real reason why. I solved it by forcing the daily execution at a particular time and in the background. Your code would then be (assuming you like to run it at 1:30 in the morning):

    $schedule->command('alert:dailly')->dailyAt('01:30')->runInBackground();
    

    What I also noticed is that I had to run commands at quarters of an hour. so (hour):00, (hour):15, (hour):30 and (hour):45 worked out, (hour):03 for example not.

    It could be a hosting issue (in my case A2hosting.com, shared) but the knowledgebase doesn’t make me any of the wiser. It’s worth the try. Run it out at a time you can monitor the process with the Linux command top -ac so you can see if the command is actually executed.

    If this works out for you, don’t ask me why. I had to find this solution for myself through trial and error.

    I’d like to point out, as explained in this PHP ‘bug’ report that your cron call never reaches the register_argc_argv=On argument. Try to run it without any arguments.

    php /home/path/domain.com/artisan schedule:run > /dev/null 2>&1

    Unless differently advised by your hosting service.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search