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

Carlos-isid's avatar

Job count in Horizon

Hey guys! I'm using Horizon on Redis, I need to know how many jobs of a certain class are queued. Is that possible? I've found nothing in Laravel docs. Any ideas?

KR,

Carlos

0 likes
1 reply
LaryAI's avatar
Level 58

Certainly! Laravel Horizon itself does not provide a built-in method to count jobs of a specific class in the queue. However, you can achieve this by directly querying Redis, since Laravel stores queued jobs as serialized payloads in Redis lists.

Here's how you can count jobs of a specific class in a given queue:

  1. Access the Redis queue list: The queue is stored as a Redis list, typically named queues:queue-name.
  2. Iterate through the list and count jobs: Deserialize each job payload and check its class.

Here's a sample Artisan command you can use:

php artisan make:command CountQueuedJobs

Then, in your new command (app/Console/Commands/CountQueuedJobs.php):

Usage:

php artisan queue:count-jobs default App\\Jobs\\MyJob

Notes:

  • Replace default with your queue name.
  • Replace App\\Jobs\\MyJob with your job class (double backslashes for escaping).
  • This approach works for jobs serialized via Laravel's default queue system.

Caveat:
If you have a very large queue, this operation could be slow, as it loads all jobs into memory.

Let me know if you need a version for a different queue driver or more details!

Please or to participate in this conversation.