Description
What were you trying to do?
.
What happened?
.
How to reproduce the bug
.
Package Versions
"nativephp/electron": "0.8.7",
"nativephp/laravel": "dev-main",
"nativephp/php-bin": "0.5.5",
PHP Version
8.3
Laravel Version
v11.34.2
Node Version
v23.3.0
Which operating systems have you seen this occur on?
No response
OS version
macOS 15.1
Notes
I tried to fix this one myself, but I think it might be beneficial to completely rethink the queue system in light of the child process rollout.
I'm not as familiar with the javascript side of NativePHP, but I think queue workers are launched here:
function startQueueWorker(secret, apiPort, phpIniSettings = {}) {
const env = getDefaultEnvironmentVariables(secret, apiPort);
const phpOptions = {
cwd: appPath,
env
};
return callPhp(['artisan', 'queue:work', '-q'], phpOptions, phpIniSettings);
}
If that's the case, there is no way this alone can be persistent. Correct me if I'm wrong, but if a process dies, it will require a full relaunch to resolve it.
Due to the memory intensive nature of the application I'm working on, queue workers are running out of memory and exiting with exit code 12. This was not being properly reported by the native:serve
dev environment, so it actually took me a little digging to even realize that the workers are crashing with exit code 12. Before learning this, from my perspective, it seemed as though the workers were arbitrarity ceasing to work.
Now, obviously for my case it is better to fix my code so it stops crashing the queue workers. But I think there might be a better solution for the way we handle queue workers as well.
To debug the crashing workers, I completely removed the queue:work
stuff from the php.ts
file (replaced them with artisan:inspire
lol), and launched the workers myself from a random livewire action:
public function queue(): void
{
ChildProcess::artisan(['queue:work'], 'test-worker', persistent: true);
}
This works like a charm. Almost.
Because we're handling the queue in a child process, every time the queue processes something, it is also considered as the child process receiving a message. The child process related events in Native\Laravel\Events\ChildProcess
are broadcasting to the queue ShouldBroadcast
vs the ShouldBroadcastNow
which is used by all other events NativePHP fires. This results in a never ending stream of broadcasts being sent to the queue worker. Not ideal. If there is no good reason to use ShouldBroadcast
, then this is a really simple fix.
I also noticed that the queue worker encounters a database lock when launched from the NativePhpServiceProvider::class
, which is why I'm launching it from a livewire method. This also needs to be resolved.
Aside from that, I really think child processes are ready to handle queue as well. At the very least, we'll get the advantage of being able to launch multiple queue workers.