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

jjudge's avatar

Can I monitor supervisord from within Laravel?

supervisord comes with a simple process monitor that serves pages on port 9100 from the server. Processes can be viewed, restarted, reloaded, logs read and tailed etc. from there, which is handy.

Does it also serve this underlying data and services through an API of some sort? Is there a library that Laravel can use to access the supervisord status, maybe view config and logs, and perhaps allow processes to be restarted?

I've not found anything to fit this requirement, but also not found anyone else asking for this. So I guess it's up in lights and I can't see it, or everyone is happy with the admin page that supervisord serves up now.

Anyone know of any way to do this?

(Just to be clear, this is about monitoring supervisord itself, not the processes that it runs. I can run queue workers to send their logs to wherever I like, so monitoring that is simple enough.)

0 likes
6 replies
jjudge's avatar

Just found this standalone application written in PHP, which shows me it can be done:

https://github.com/mlazarov/supervisord-monitor

I guess the guts of that application need to be ripped out into a separate package, so the communication with supervisord and the front end can be separated.

Helmchen's avatar

Forge does this - so it has to be possible somehow

For Laravel there is https://horizon.laravel.com/ - I've never looked at the details to be honest.

to restart the queue there is php artisan queue:restart and if you want to restart a specific worker, i would probably just kill the process, supervisor will restart it anyway.

Laravel itself uses redis to communicate with the workers, so maybe you can hook into it to build your own little process monitor? :)

if there really isn't anything for laravel already and you want to start something on github, i would be happy to help you. We could use that as well.

jjudge's avatar

Just found this:

https://github.com/yzalis/Supervisor

Works like a dream, though has a big stack of zend dependencies. It probably needs a little expansion to cover some of the functions it does not cover yet (e.g. it can restart all processes, but not restart an individual process).

-bash-4.1$ composer require yzalis/supervisor
Using version ^1.1 for yzalis/supervisor
./composer.json has been updated
Loading composer repositories with package information                                                Updating dependencies (including require-dev)         Package operations: 14 installs, 0 updates, 0 removals
  - Installing zendframework/zendxml (1.0.2): Downloading (100%)
  - Installing zendframework/zend-stdlib (3.1.0): Downloading (100%)
  - Installing zendframework/zend-eventmanager (3.2.0): Downloading (100%)
  - Installing zendframework/zend-code (3.3.0): Downloading (100%)
  - Installing zendframework/zend-server (2.7.0): Downloading (100%)
  - Installing zendframework/zend-math (3.0.0): Downloading (100%)
  - Installing container-interop/container-interop (1.2.0): Downloading (100%)
  - Installing zendframework/zend-validator (2.10.2): Downloading (100%)
  - Installing zendframework/zend-escaper (2.5.2): Downloading (100%)
  - Installing zendframework/zend-uri (2.5.2): Downloading (100%)
  - Installing zendframework/zend-loader (2.5.1): Downloading (100%)
  - Installing zendframework/zend-http (2.7.0): Downloading (100%)
  - Installing zendframework/zend-xmlrpc (2.6.2): Downloading (100%)
  - Installing yzalis/supervisor (1.1.0): Downloading (100%)
jjudge's avatar

@Helmchen horizon is pretty much just for redis at the moment. I'm using azure to service the queues, so redis isn't even in the picture here.

php artisan queue:restart is preferable to just killing the process, since it signals the process to die as soon as it has finished its current job. Ideally you don't want to kill a worker while it is in the middle of a job.

I've found a package that talks to supervisord really well (it worked for me straight away without any effort) so I might just create a Laravel wrapper for that (to handle the service provider and config settings) assuming it has not already been done. It uses XML-RPC to talk to supervisord, and get statuses, logs, process IDs, tell it to restart or signal processes etc.

Remember, this is just the supervisor. It sits there doing nothing for 99.999% of the time, just keeping an eye on the artisan processes, restarting them if they die. I could tell it to restart a process at any time, and would need to do that if any new code is released. However, I probably don't want to do that, as it will involve the jobs being killed. Instead I want to send the artisan worker(s) an event (something this package supports) to tell the artisan worker to die when it is good and ready. Then supervisord will kick in after noticing it gone and restart it.

Monitoring what is happening on the queues is another level, and there are good laravel packages to help with that. I've not worked out how to throw a failed job back on its original queue via the web interface though (it kind of works, then ends up trying to run a CLI command by invoking the full php executable path, which is protected since it is outside the permitted web root. But that's another problem for another day.

jjudge's avatar

I'll explore this a little more over the weekend, and post back here with what I'm going to do about it. If it's a new wrapper package, then it will be open for additions/suggestions. I think all the pieces are there, some maybe needing a fresh coat of paint, but otherwise solid.

1 like

Please or to participate in this conversation.