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

kmnurunnabi's avatar

Laravel Scheduler with Job

I was using scheduler with a job class. As I know in laravel, Job class are generally works on queue that processed by worker command. But, when I run php artisan schedule:work, It's processing job whenever the time reaches. Then what is the purpose of queue inside a scheduler when job can process itself?

0 likes
5 replies
tisuchi's avatar

@kmnurunnabi

TLDR

In short, the Scheduler initiates tasks, and the Queue manages their execution.

The Laravel Scheduler is used to schedule tasks at specific intervals, while Job Queues handle time-consuming tasks asynchronously. When you use the Scheduler to trigger a Job, you have two options:

  • Run the job immediately within the Scheduler (synchronous).
  • Dispatch the job to the Queue (asynchronous).

Dispatching a job to the queue from the Scheduler allows for efficient, background processing of resource-intensive tasks without burdening the Scheduler. This separation enhances performance and error handling, especially for large applications.

1 like
kmnurunnabi's avatar

@tisuchi How can we send a job inside queue table when it's triggered by scheduling tasks?

Snapey's avatar

@kmnurunnabi The scheduler just creates the job and places it on the queue.

Sometime later, the job is processed by the queue worker

tisuchi's avatar

@kmnurunnabi I am not clear what you mean by that:

How can we send a job inside queue table when it's triggered by scheduling tasks?

Ok, maybe I give you a real-life example:

Imagine a restaurant where customers place their orders with the waiter. Instead of the chef cooking each order immediately, the orders are placed in a line (queue). The chef then cooks each order one by one. This way, even if many orders come in at once, the chef doesn't get overwhelmed and can focus on making each dish properly. The waiter (scheduler) ensures orders are taken at the right time, but the chef (queue worker) decides the best time to cook them.

1 like

Please or to participate in this conversation.