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

JustinM's avatar

Queue Worker in Forge gives error, but not if done manually.

Since we are scaling up our operations by about 5x in January I wanted to take server management off my plate and set up Forge last night.

All went according to plan, except people can no longer receive queued emails or sms messages. a little bit of digging in the logs shows that the queue worker I set up in forge is tossing this error on every job:

[2020-12-11 17:46:45] production.ERROR: Trying to access array offset on value of type null {"exception":"[object] (ErrorException(code: 0): Trying to access array offset on value of type null at /home/forge/EXAMPLE.COM/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php:156)

[stacktrace]

#0 /home/forge/EXAMPLE.COM/vendor/laravel/framework/src/Illuminate/Queue/QueueManager.php(156): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError()

...

}

After doing a bit of investigation I noticed that the culprit appears to be the connection name, I provided mysql since that's the name of my database connection and in .env my QUEUE_DRIVER is set to database. Doing so generates a worker config like this:

[program:worker-326584]
command=php7.4 /home/forge/EXAMPLE.COM/artisan queue:listen mysql --sleep=10 --quiet --delay=5 --tries=3 --queue="default"

process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=2
stdout_logfile=/home/forge/.forge/worker-326584.log

It was confusing me because if I ran the queue in the terminal (without connection name) it ran with no issues, so I added my own queue worker config to /etc/supervisor/conf.d and it is running fine... However, I want to be able to manage these in Forge if possible.

My queue worker (that works) looks like this:

[program:worker-ns4]
command=php7.4 /home/forge/EXAMPLE.COM/artisan queue:listen --sleep=10 --quiet --delay=5 --tries=3 --queue="default"

process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=2
stdout_logfile=/home/forge/.forge/worker-ns4.log

So what gives? They are virtually the same, except mine omits the connection name that forge is forcing me to provide.

Any ideas how I can get this to work in Forge?

0 likes
3 replies
srasch's avatar

Could you provide more content, maybe the job class you want run?

JustinM's avatar

It's not even making that far, all jobs fail from Forge's queue worker, all jobs pass when I use my own worker that is exactly the same with the exception I omit "mysql".

the majority of the jobs in the system are queued notifications that send out an email (mailgun) and/or sms (nexmo) message based on the users notification preferences.

These notifications are pretty standard, just Notification classes that extend Notification, implement ShouldQueue and use Queueable...

class TestNotification extends Notification implements ShouldQueue
{
    use Queueable;
    // typical via, toMail, toNexmo, and toArray methods in here...
}

The notifications have been working fine for years on our previous EC2 that wasn't managed by forge, and still run fine on the forge managed EC2 assuming I use my own worker config posted above.

I would just like for the forge managed worker to work properly so that I can manage it from within forge.

JustinM's avatar
JustinM
OP
Best Answer
Level 4

I figured it out after testing a bit on a separate server.

Turns out connection needs to correlate to an index in the connections database in config/queue.php and not the database driver you are using.

Since I was listing "mysql" instead of "database", it was unable to find that connection. Which seems pretty obvious now.

I ended up at this solution after reading the forge docs, which directed me to the queue docs, which makes mention of it needing to correlate to an option in the config file. Would have been nice to have an option to omit the connection (see above how my worker works fine without it) or have the default options in a drop down with the ability to type in custom ones. Oh well, that is neither here nor there.

Hope this helps someone else that may have overlooked this.

1 like

Please or to participate in this conversation.