No Supervisor? No Problem! Run Laravel 12 Queue Workers via Cron in CWP

Author

Kritim Yantra

Jul 08, 2025

No Supervisor? No Problem! Run Laravel 12 Queue Workers via Cron in CWP

You're deploying a Laravel project on a shared server using Control Web Panel (CWP). You’ve got jobs queued up — sending emails, processing orders, resizing images...

But you ask yourself:

“How do I run queue:work without keeping a terminal open forever?”

Well, you're not alone — and you don’t need Supervisor or a dedicated worker process to handle this. Laravel gives us a neat, cron-based solution that works great even on limited hosting environments.

Let’s walk through it together — step by step, zero confusion, 100% working! 💡


📌 Why This Matters (Even If You’re New)

Laravel queues are essential for performance — they allow your app to defer time-consuming tasks like:

  • Email sending 📧
  • Video processing 🎬
  • API calls 🌍

But by default, jobs just sit there in the queue.

To process them, you need to run:

php artisan queue:work

But this keeps running forever… which is not practical on shared hosting or CWP. 😩


✅ The Smart Way: Use Cron + Laravel’s Scheduler

Here’s the game plan:

  1. We schedule Laravel to run a safe version of queue:work.
  2. We trigger Laravel’s scheduler every 5 minutes using a cron job.
  3. Boom — your jobs are processed, hands-free! 🎉

Let’s break it down.


🛠 Step 1: Use Laravel’s Built-In Scheduler in routes/console.php

Works beautifully in Laravel 11+, no need to touch Kernel.php.

Open this file:

routes/console.php

And add the following at the bottom:

use Illuminate\Support\Facades\Schedule;
use Illuminate\Support\Facades\Log;

Schedule::command('queue:work --stop-when-empty')
    ->everyFiveMinutes()
    ->withoutOverlapping()
    ->before(function () {
        Log::info('[Schedule] Queue worker started at ' . now());
    })
    ->after(function () {
        Log::info('[Schedule] Queue worker finished at ' . now());
    });

✨ What This Does:

  • queue:work --stop-when-empty: Processes all pending jobs and exits.
  • everyFiveMinutes(): Runs every 5 minutes (adjustable).
  • Logging: Writes to storage/logs/laravel.log so you can track it.

⏰ Step 2: Set Up Cron in CWP

Go to:

CWP ➜ User Panel ➜ Cron Jobs ➜ Add Cron Job

Then use the advanced time options:

🔧 Fill it like this:

📥 Command:

cd /home/appmdlst/public_html/appsys-api && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1

(Adjust paths based on your Laravel project and PHP location.)

🕐 Time Settings (Advanced):

Minute: */5
Hour: *
Day: *
Month: *
Weekday: *

This tells cron:

Run the Laravel scheduler every 5 minutes.

📌 Description:

Laravel Queue Scheduler (every 5 min)

Click "Save cron" — done! 🎯


🔍 Real Example: Processing Email Jobs Automatically

Let’s say you dispatch a job like this:

SendWelcomeEmail::dispatch($user);

Laravel pushes it into the queue.

Now, every 5 minutes, the scheduler will:

  • Detect that there are jobs.
  • Start a worker with queue:work.
  • Process them.
  • Exit safely.
  • Log the start/finish.

No manual effort. No supervisor. No hanging terminal. ✅


🧪 How to Test It

Here’s a simple test route:

use App\Jobs\SendTestNotification;

Route::get('/test-job', function () {
    SendTestNotification::dispatch();
    return 'Job dispatched!';
});
  • Visit /test-job in the browser.

  • Wait 1–5 minutes.

  • Check storage/logs/laravel.log.

  • You should see:

    [Schedule] Queue worker started at 2025-07-07 15:10:00
    [Schedule] Queue worker finished at 2025-07-07 15:10:01
    

💡 Tips & Notes

🟢 No jobs?
Even if the queue is empty, Laravel will still run queue:work --stop-when-empty, see there’s nothing, and exit. You’ll still get logs.

Need faster processing?
Change both the cron and Laravel schedule to everyMinute() for near-instant job handling.

💻 PHP path wrong?
Run which php in CWP terminal and replace /usr/local/bin/php with the correct one.


🧠 Wrap-Up: What You Learned

✅ Why queues matter
✅ How to use Laravel’s scheduler in Laravel 11+
✅ How to schedule queue:work safely
✅ How to automate it using CWP cron
✅ How to track execution using logs

No need for Supervisor or root access — just clean Laravel + CWP cron power! 🔥


💬 Your Turn!

Try this in your Laravel 11+ project and let me know how it works.
Have you used queues before — or is this your first time? Leave a comment below 👇


❓FAQ – Common Questions

1. What if no jobs are in the queue?

No worries — queue:work --stop-when-empty just exits immediately. Logs will still show the run.


2. Can I run this every minute instead of 5?

Yes — just change everyFiveMinutes() to everyMinute() and set your cron time as * * * * *.


3. Where do I see log output?

Check storage/logs/laravel.log. You’ll find entries like:

[Schedule] Queue worker started...
[Schedule] Queue worker finished...

Tags

Comments

No comments yet. Be the first to comment!

Please log in to post a comment:

Sign in with Google

Related Posts