Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bramcou's avatar

Laravel queue worker stops after 15min if started via task schedule but keeps running if started from CLI

Hi all,

I've been running a Laravel website on shared hosting for a couple of years now with a email queue setup. In the process of switching to a new (shared) host and I'm running into trouble with the queue worker.

On the previous host the queue worker kept running for weeks, never needed a restart (only when I forced one after updating the website).

Since I'm on a shared hosting environment I can't install supervisor (do have SSH access) so I use the task scheduler to verify whether the queue worker is still running and if it isn't, the task scheduler restarts the queue worker.

Code to verify if the queue is running:

$path = $this->getPath();

        if (file_exists($path . '/queue.pid')) {
            $pid = file_get_contents($path . '/queue.pid');
            $result = exec("ps -p $pid --no-heading | awk '{print }'");
            return $result == '' ? false : true;
        }

        return false;

And the code to restart the queue worker, if it has stopped:

$command = 'php /laravel/artisan queue:work --delay=10 --timeout=30 --sleep=10 --tries=3 > /dev/null & echo $!';
        
        $number = exec($command);
        file_put_contents($path . '/queue.pid', $number);

The task scheduler runs this task every minute. After 15 minutes the queue worker stops and the task scheduler restarts it. When I start the queue worker from the CLI it keeps running for hours, no sweat, as long as I keep my CLI terminal open.

When I close my CLI terminal and then restart my CLI and run 'ps aux' the process is still running however (logically) no longer owned by my CLI. In that case, the queue worker also stops after 15 minutes.

No errors in my laravel.log or send to sentry.

  1. Could this be anything else then my hosting environment auto killing unowned processes after they've run for 15 minutes?

  2. Would it be troublesome to work in this configuration with my task scheduler checking the queue worker every minute and then auto restarting the worker every 15 minutes?

  3. sub question: on this new host I have access to a 128mb redis. Used to use the database driver for the queue and now wondering if I should switch to redis. From what I've found on the web it would appear redis would only be preferential when running heavy queue's. Our queue handles, tops, some 100-200 emails a hour, usually no more than 10-20 a hour.

I've figured that I could ask the host if they can allow me to 'whitelist' my queue worker but they pretty clearly state that running deamons isn't allowed in the first place so I think that's probably only gonna get me in trouble..

Always easier to say sorry afterwards then to ask permission beforehand (-:

Cheers!

0 likes
4 replies
Robstar's avatar

With the greatests respect, this setup demonstrates one thing only. You urgently need to use a none shared host. AWS for example are dirt cheap.

The majority of shared hosts will not allow long running processes and daemons. I'm sure your host has something their end to automatically kill such processes.

Supervisord is exactly what shared hosts don't want you to be using as the queue worker for example is running permanently and always consuming resources. By definition, you're on a shared host.

Instead of trying all this, simply migrate to a server where you have control. You can setup a cheap AWS server within a 10 or 15 minutes (with ssl, queue worker, redis, databases, auto deployments etc.) using Laravel Forge.

Hell, the majority of shared hosts don't even have Git available.

1 like
bramcou's avatar

Thanks for your opinion guys.

The only reason that I didn't do that yet is costs, forge would cost us $120 a year + the AWS or DO costs. From what I've read DO is more cost efficient but depending if we'd need either 1 or 2 GB of RAM it would be another $60 or $120 a year. The shared hosting features everything we need except for this part but costs a little under $100 a year.

It's a website for a sports association and I just wanna keep costs to a minimum since eventually, all the members are paying for it.

If I'm missing other advantages or am really misinterpreting the situation, please be blunt (-:

bramcou's avatar

On a side note, if switching to AWS or DO, how much CPU and Memory does a Laravel site need. It serves about 250 unique visitors a day, perhaps up to 30 simultaneous and is mainly an administrative website. Not heavy on images or caclulations, just regular db query's and the likes.

Please or to participate in this conversation.