How To Use Laravel Queue on CPanel

80 Views Asked by At

I am developing a web application with laravel. And I need to use laravel queue jobs. I wrote queue job and it works well if I run laravel queue worker by using

php artisan queue:work

But in production when I run that command using terminal provided by CPanel, it stops after a few days.

I searched answers for several days but didn't find answer. Many of them suggest installing supervisor but CPanel is shared hosting and I can't have root access for installing it. Also some suggest using cron job but then it will create too many laravel queue workers after a period of time because it creates new worker each time the cron job calls.

Can anyone help me? Thanks in advance

1

There are 1 best solutions below

5
Lorenzo Lorini Kalil On

You can use a cron that destroys the current worker and creates a new one with the flag --once

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