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

Burano's avatar

Laravel Job "Finishing" before all code has executed?

So I'm currently in a situation where I'm writing a project that "extends" a forum software called Xenforo.

Inside my app, I've basically got some jobs setup so that once a payment webhook gets sent from Stripe, it gets put on a queue, and the a worker processes it and gives the user a usergroup on the forum. The code for that looks like this;

        $service = Xenforo::getApp()->service('XF:User\UserGroupChange');
        $service->removeUserGroupChange($this->forum_id, $key);

However, when my job executes it would appear that it finishes before the usergroup change "completes".

So it DOES call the function that is supposed to change the usergroup, but that function itself relies on a lot of other stuff inside XF, and I'm not sure exactly how "long" it takes, but it would appear the job ending is cutting it off as when I check the XF database, there is still records laying around in there, just not fully finished, and it also fully executes the code after it as well.

On top of that, if I just add a controller and a button to my application to add/remove user groups, it works flawlessly every single time. So 100% the Job/Queue is playing a factor here I think.

Hopefully someone can give some additional information. Even if you know nothing about XF, if you can share any information on why the Job/Queue is behaving like this I would be very grateful.

0 likes
1 reply
Doeke's avatar

A job on a queue is handled by a separate php process. A runner is constantly checking if there is a job to be executed. So when your request add's a job to the queue, the runner can pick it up at the same time, and run the job; while your request is still finishing up.

Queues are a great way to speed up the request itself by moving some logic to a background task, but the timing has to be right.

My advice would be to add the job with an event hook that is fired when the change of the user group is done. So you'll have to see if that software provides an event for that scenario.

Please or to participate in this conversation.