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

meetgodhani's avatar

What is the best way to show progress of queue to user?

Hi

How do we show progress of a queue job and notify user when job is completed or finished using Laravel 5?

0 likes
2 replies
c.schmidl's avatar

Hey there,

I have the same problem right now and didn't find a simple technique built in Laravel 5.2 which would solve it right away. Nevertheless, I have this (somehow inconvenient) idea how a user can get notified of the progress of queue jobs by connecting well known Laravel-features.

  • Create a table in your database for your Queue Jobs (id, description, user_id, progress, created_at, updated_at). Or create your own fields. Whatever makes sense to you.
  • Right before a job is pushed to the Queue (e.g. from your Controller), create a new table entry for a Queue Job and set the corresponding fields as stated above and save the corresponding id. Set the progress to "received", "waiting", 0 or anything you can imagine as a progress status to begin with.
  • Push the job to the Queue and give the job the id received before and the user_id from the user who triggered the job.
  • Inside a Job 's handle-method you should fire an Event like JobProgressHasChanged whenever you want to inform the system of a progress update and give JobProgressHasChanged the updated fields as parameters.
  • The JobProgressHasChangedListener receives the event and updates the entry in the Queue Jobs table.

Now comes the part where you can implement anything you want to inform the user of the progress of his jobs. You can implement a Controller whose whole purpose is to provide a route the user can contact by an Ajax-Request every second. The route would produce a list in Json-format from the users's Jobs out of the Queue Jobs table.

I know that polling the status of one's jobs is not an elegant thing. The other option is covered right here: https://laracasts.com/lessons/broadcasting-events-in-laravel-5-1

The solution involving Pusher seems to be a much better approach here.

with kind regards, Christoph

4 likes
tristanbailey's avatar

@c.schmidl thanks for the suggestion. Do you have any thoughts on dealing with a progress that is not 100 know at the start? I have some Jobs that will start more Jobs under right conditions so 1 job sent, which spawns 100 jobs to curl pages. Then under next job it might do some other task. So total for the progress goes from /1 > /101 > /120. I feel I need to adjust the total.

Maybe though just having one queue of jobs sent with a parent_id I can just keep sum(jobs_done) / sum(jobs_in_queue) and it would keep up as it would create the new total each time.

For efficiency I could have the Event send back, update status & send the new totals to a cached value, to speed it up.

Please or to participate in this conversation.