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

ctrlaltdelme's avatar

Queued Job locking up localhost - cannot interact with site while job is queued

I'm working on setting up a Job to import movies from the TMDB API (they can take some time and I don't want to interrupt the user). I can successfully dispatch the job, warn the user if they try to start a job with the same ID, but while the Job is in "RUNNING" status, I literally cannot do anything on 127.0.0.1 😭

The code that is causing the issue:

And the Controller responsible for handling the action

My understanding of queues and locks and this stuff is rudimentary at best. I understand the concept, but can't put it into practice really ever. I need some help understanding what is causing this complete deadlock here. Thanks!

0 likes
32 replies
Snapey's avatar

are you using artisan serve? Its single threaded.

Maybe you have queues configured to sync

1 like
ctrlaltdelme's avatar

@Snapey Hello! I'm using Herd. Does that make a difference? Herd is running nginx and PHP for me while PhpStorm is running Vite (npm run dev)

Snapey's avatar

@ctrlaltdelme ok so you should be able to do multiple things at once. How are your queues configured?

Sinnbeck's avatar

@ctrlaltdelme If you are using herd, your domain should be something like myproject.test, not 127.0.0.1 or localhost? Or do you just mean that you cannot use any other sites on herd as well ?

ctrlaltdelme's avatar

@Sinnbeck heya! I mean that while the job is running, I can't interact with my own site. I can't click a link to another page. It makes the request but then I eventually get a Laravel error for a timeout

ctrlaltdelme's avatar

@Snapey I haven't done anything extra. It's all the defaults from what I can tell. But, to help provide more context, where should I look to provide the code for you?

Sinnbeck's avatar

@ctrlaltdelme Ok so you do visit the site on somedomain.test or similar ?

Check your .env for QUEUE_CONNECTION=. Try setting it to redis

ctrlaltdelme's avatar

@Sinnbeck yeah, domain.test. If I set it to redis, do I need to install redis or sign up for redis?

EDIT: Oh I see in the docs. Looks like I can just change to redis. Is there anything else to change to test what's going on?

ctrlaltdelme's avatar

@Sinnbeck oh yeah it's running. That's the problem. While the worker is running and the job is running, I can't do anything

Sinnbeck's avatar

@ctrlaltdelme Just to be sure I understand. The controller call to findOrCreate returns the redirect and that page renders fine. But after that it locks?

If you dont dispatch the job, does it then work?

ctrlaltdelme's avatar

@Sinnbeck Yeah! The first call works fine and the job queues and runs and performs the redirect with the success status. But after that, it locks. If I don't dispatch the job I imagine it sends it to the queue anyway. Am I not supposed to have the worker running while the app is running?

Sinnbeck's avatar

@ctrlaltdelme Yeah the queue worker should be running. That is correct. So its a bit weird. But did it work if you just comment out this line?

//                ImportMovieJob::dispatch($type, $id);
ctrlaltdelme's avatar

@Sinnbeck I'll have to test but while I'm getting ready to leave for work this morning, I got this for you.

BROADCAST_CONNECTION=log
FILESYSTEM_DISK=local
QUEUE_CONNECTION=database

CACHE_STORE=database
CACHE_PREFIX=

MEMCACHED_HOST=127.0.0.1

REDIS_CLIENT=phpredis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

I noticed the /config/database.php wants a REDIS_USERNAME but one isn't set. Is that normal? And should I still try redis once I get the chance to test?

Sinnbeck's avatar

@ctrlaltdelme Yeah give redis a chance. The problem could be due to some database locking, and redis would avoid that

ctrlaltdelme's avatar

@Sinnbeck in my Job and Controller I am calling lock. Should I not be? I'm just trying to prevent duplicate jobs and was trying to follow the docs. There wasn't a cookbook or step by step so was trying to use my existing knowledge of queues to work it out.

ctrlaltdelme's avatar

@Sinnbeck Well I added that to my Job and now both windows queue the job instead of locking. Not quite what I want still, but better than locking the entire application lol. Here's an updated Controller. I deleted the other locking lines I had. I think I need to check for something in the Controller but I've looked over the docs and while the documentation is very good, I can't tell how to put everything together.

Job

ctrlaltdelme's avatar

To add to this. When I add the uniqueId() and uniqueFor() methods back into the Job, the second window no longer pushes another job, but I saw this in the db immediately after executing both.

https://imgur.com/a/Hq4qkrk

Updated Job after adding methods back for testing:

Still think I need to handle it somehow elsewhere? But maybe not lol. I know we keep saying redis, but I really want to figure out what is blocking this so I can learn

ctrlaltdelme's avatar

@Sinnbeck I did not. Still trying to figure out why it isn't working with the database queue driver. Just want to troubleshoot this one and understand why its blocked. I'll change to redis once that's done and see if I still have issues.

Snapey's avatar

I still can't get past the fact that you said requests to 120.0.0.1 are blocked ?

ctrlaltdelme's avatar

@Snapey That's probably my mistake. I just meant that I can't do anything on the domain that is being served by Herd, domain.test. I assumed it was running on localhost, but using a virtual host to map it to the domain. My mistake, if so. Regardless, I'm locked from doing anything on the site when a job is running using the database connection. I just want to figure out why.

ctrlaltdelme's avatar

@Snapey Sure thing. Here's the output:

Snapey's avatar

@ctrlaltdelme no, seems fine.

What happens if you have no queue worker running? Sorry if you already said this

ctrlaltdelme's avatar

@Snapey No queue worker running it works perfect! No identical job id can be queued and everything works as I'd expect. I will have to do Redis I suppose, but I'm working on Windows so it's kind of a pain.

Snapey's avatar

@ctrlaltdelme somehow you seem to be restricted to a single thread, which is a problem usually associated with artisan serve. If you quit Herd, does your webpages still get served?

1 like
ctrlaltdelme's avatar

@Snapey if I quit Herd, do I run artisan serve inside PHPstorm since Herd will no longer be serving it? ATM, I'm just running npm run dev in PhpStorm

Snapey's avatar

@ctrlaltdelme Im wanting to confirm that it is herd doing the web serving, so, if you stop Herd I expect your requests to fail.

Sometimes its a good check to deliberately break something and see that it fails as you expect.

Please or to participate in this conversation.