Master Supervisor to Supercharge PHP Background Tasks on Ubuntu
This guide explains how to install Supervisor on Ubuntu, configure it for Laravel queue workers, and apply practical tips such as multi‑process management, timeout control, log monitoring, and Docker integration to improve PHP backend task efficiency and stability.
Overview
In PHP development, especially for background jobs, queue processing, or long‑running processes, efficiency and stability are critical. Supervisor is a powerful Linux‑based process control system that can automatically manage these tasks, keep them running, and restart them on failure.
What Is Supervisor?
Supervisor is a Linux‑based process control system designed for managing background processes. It monitors process status via configuration files and automatically restarts processes that exit unexpectedly, reducing manual intervention. It is well suited for PHP developers to manage queue workers, scheduled scripts, or WebSocket services.
Installation and Basic Configuration
On Ubuntu, install Supervisor and create a program configuration for a PHP worker.
sudo apt-get update
sudo apt-get install supervisorThe configuration files are usually located in /etc/supervisor/conf.d/. Create a new file such as php_worker.conf to manage a PHP process.
Configuring a Laravel Queue Task
Example program:laravel_queue configuration:
[program:laravel_queue]
command=php /var/www/myproject/artisan queue:work --tries=3
autostart=true
autorestart=true
user=www-data
stderr_logfile=/var/log/laravel_queue.err.log
stdout_logfile=/var/log/laravel_queue.out.log command: the PHP command to run, here the Laravel queue worker. autostart: true to start the service with Supervisor. autorestart: true to restart the process automatically after a crash. stderr_logfile and stdout_logfile: paths for error and output logs.
After saving the file, reload Supervisor configuration:
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start laravel_queuePractical Tips for Better Efficiency
Multi‑process management : use the numprocs option (e.g., numprocs=4) to run several workers in parallel and increase throughput.
Timeout control : set stopwaitsecs to define how long Supervisor waits for a process to stop, preventing resource waste.
Log monitoring : regularly inspect log files and refine task logic to reduce error rates.
Combine with Docker : embed Supervisor configuration inside a Docker container for easier migration and team collaboration.
Properly configured Supervisor gives PHP developers a reliable tool for handling complex background tasks, improving both performance and stability.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
