brobrobrobrobro
brobrobrobrobro

Reputation: 314

Laravel task scheduler doesn't work

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?

Upvotes: 3

Views: 9450

Answers (3)

yahya_iyaseh
yahya_iyaseh

Reputation: 1

Use php artisan command:get-attendances Command.

It will provide you with a list of run commands.

Upvotes: 0

Dimitri Mostrey
Dimitri Mostrey

Reputation: 2355

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.

Upvotes: 0

Andrius Rimkus
Andrius Rimkus

Reputation: 653

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

Upvotes: 1

Related Questions