3

I tried to run scheduler in laravel 5.3 with the following code in App/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->command('queue:work')->everyMinute()->withoutOverlapping();
}

and set cron jobs in my shared hosting with the following:

* * * * * php /home/username/public_html/laravel/artisan schedule:run >> /dev/null 2>&1

but it doesn't work in my shared hosting

I used database driver for my queue, and the attempts still 0, which is the queue is not execute by the task scheduler.

Anyone can help me with this problem?

brobrobrobrobro
  • 315
  • 4
  • 18

3 Answers3

1

A few things you might want to check:

queue:work

Note that once the queue:work command has started, it will continue to run until it is manually stopped or you close your terminal. https://laravel.com/docs/5.3/queues#running-the-queue-worker

Are you sure you want to spawn a new process with the Scheduler every minute?

powering scheduler

artisan schedule:run command needs to be run every minute in order for the Scheduler to work. This might be done with the cron: https://laravel.com/docs/5.3/scheduling#introduction

Andrius Rimkus
  • 643
  • 5
  • 10
  • Sorry, i'm not explanied yet that I've set the cron jobs with I've set the cron jobs, every minute "* * * * * php /home/username/public_html/laravel/artisan schedule:run > /dev/null 2>&1" – brobrobrobrobro Feb 06 '17 at 02:21
  • So does the Scheduler work in your local environment? Also, write your own simple command which logs something and try to schedule it. – Andrius Rimkus Feb 06 '17 at 02:30
0

This link might be helpful to setup scheduler. I have done with this.Please try.

https://www.sitepoint.com/managing-cronjobs-with-laravel/

0

I use shared hosting on A2hosting and the command that works for me is

nohup php artisan queue:work &

The & assures the command keeps running and with nohup the process won't be killed even if you exit or close the terminal.

UPDATE: If you can run shell commands from PHP, this is the solution I have eventually implemented. After 3 days it works as expected. Only one instance of queue:work runs and it only restarts when it stopped running. The schedule is running every minute.

if ( ! strstr(shell_exec('ps xf'), 'php artisan queue:work'))
    {
        $schedule->command('queue:work')->everyMinute();
    }

You may also search on queue:work instead of php artisan queue:work. Run shell_exec('ps xf') in tinker and see what you get.

Dimitri Mostrey
  • 2,302
  • 1
  • 12
  • 11