DEV Community

Cover image for Laravel Worker with Supervisor: Automate Your Way Out of Manual Madness
Jagadish Ranasthala
Jagadish Ranasthala

Posted on

Laravel Worker with Supervisor: Automate Your Way Out of Manual Madness

Hey folks,
We all know that most mind-numbing, repetitive tasks can be offloaded to automation - and nothing beats the good old cron job when it comes to routine work

Case in Point: Employee Attendance
Let's say you need to log employee attendance daily.
The old-school way might look like this:

HR (shouting from her cabin): "Alex…"
Alex: "Present, ma'am!"

hr

Charming, but inefficient.
With Laravel (our multitasking superhero) and Supervisor, we can automate this cleanly - especially if you're using biometric devices and APIs (thanks to APIs for making data fetching simple).

Step-by-Step: Automating Laravel Scheduler with Supervisor

1. Install Supervisor

sudo apt update
sudo apt install supervisor
Enter fullscreen mode Exit fullscreen mode

Check if Supervisor is installed properly:

supervisord --version
Enter fullscreen mode Exit fullscreen mode

2. Create a Laravel Worker Config
Edit or create the Supervisor config file:

sudo nano /etc/supervisor/conf.d/laravel-worker.conf
Enter fullscreen mode Exit fullscreen mode

Paste the following config (update paths and user as per your setup):

[program:laravel-scheduler]
directory=/home/ranasthala-dev/team-app
command=bash -c 'php /var/www/html/artisan schedule:run 2>&1 | grep -v "No scheduled commands"'
autostart=true
autorestart=true
user=jagadish
redirect_stderr=true
stdout_logfile=/home/ranasthala-dev/team-app/storage/logs/laravel-scheduler.log
Enter fullscreen mode Exit fullscreen mode

3. Start and Manage the Worker

sudo supervisorctl reread       # Detect new programs
sudo supervisorctl update       # Apply new config
sudo supervisorctl start laravel-scheduler
sudo supervisorctl status       # Check if it's running
Enter fullscreen mode Exit fullscreen mode

4. Check Log Output

tail -f /home/ranasthala-dev/team-app/storage/logs/laravel-scheduler.log
Enter fullscreen mode Exit fullscreen mode

This will show you real-time logs from your scheduler.

Why This Rocks

  • No need to rely on crontab entries.
  • Your scheduler runs as a background process and restarts automatically if it fails.
  • Logs give you a direct view into task execution.

So, the next time your HR shouts across the office, let Laravel and Supervisor answer back with a silent but efficient "present!"

Top comments (0)