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

sjelfull's avatar

Running Laravel Queue standalone (5.4)

I'm trying to run Laravel Queue standalone, and I've been following the guide here: http://masnun.com/2015/05/24/using-laravel-queues-standalone-outside-laravel.html - although I'm implementing a Redis-backed queue.

This guide wasn't quite up to date with the latest changes, so I had to modify my code.

namespace Craft;
use Illuminate\Encryption\Encrypter;
use Illuminate\Queue\Capsule\Manager as Queue;
use Illuminate\Queue\Worker;
use Illuminate\Queue\WorkerOptions;

class QueueCommand extends BaseCommand
{
    public function actionWork ()
    {
        $queue = new Queue;

        $queue->getContainer()->bind('encrypter', function () {
            return new Encrypter('foobar');
        });

        $queue->addConnection([
            'driver' => 'redis',
            'host'   => 'localhost',
            'queue'  => 'default',
        ], 'default');

        $dispatcher       = new \Illuminate\Events\Dispatcher();
        $exceptionHandler = new ElasticSearch_ExceptionHandler();
        $worker           = new Worker($queue->getQueueManager(), $dispatcher, $exceptionHandler);

        // Run indefinitely
        $options = new WorkerOptions([ 0, 128, 60, 2, 3 ]);
        $worker->daemon('default', 'default', $options);
    }
}

This is what I currently got, and it gives me the following error:

Stack trace:
#0 /vendor/illuminate/queue/Worker.php(119): Illuminate\Queue\QueueManager->isDownForMaintenance()
#1 /vendor/illuminate/queue/Worker.php(75): Illuminate\Queue\Worker->daemonShouldRun()
#2 /consolecommands/QueueCommand.php(69): Illuminate\Queue\Worker->daemon('default', 'default', Object(Illuminate\Queue\WorkerOptions))```
0 likes
5 replies
jerlandsson's avatar

I solved this a few days ago.

I created a Container class that extends the Laravel Container and added the isDownForMaintainance() method that only returns false (we don't use that type of maintainance in our product).

Like this:

<?php
namespace My\Namespace\;

use Illuminate\Container\Container as IlluminateContainer;

class Container extends IlluminateContainer {

    /**
     * Determine if the application is in maintenance mode.
     * @return bool
     */
    public function isDownForMaintenance() {
        return false;
    }
}

If you haven't solved it yet, hope that helps.

Jonas

jerlandsson's avatar

Also - the workerOptions params shouldn't be passed as an array, but rather different params. Like this:

$worker->daemon(
    'default',
    'default',
    new WorkerOptions(60, 256, 180, 0, 5, true)
);
hakuno's avatar

You don't need to do that with the service container.

The right thing to do is simply:

$app = new Laravel\Lumen\Application(realpath(__DIR__));
...
$queue = new QueueManager($app);

Then your manager is able to understand the following:

    /**
     * QueueManager.php
     * Lines 246-254
     */
    public function isDownForMaintenance()
    {
        return $this->app->isDownForMaintenance();
    }

By the way, the __construct's QueueManager below

void __construct(Application $app)

All right!

1 like
virajkhatavkar's avatar

Hey RM, I am implementing a custom queue in a Cake project. I have pretty much done with it. Would you be so kind to let me know how would you delete a job after it is processed?

Please or to participate in this conversation.