Download the PHP package yangusik/laravel-balanced-queue without Composer

On this page you can find all versions of the php package yangusik/laravel-balanced-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-balanced-queue

Laravel Balanced Queue

A Laravel package for queue management with load balancing between partitions (user groups). Perfect for scenarios where you need fair job distribution and concurrency control per user/tenant.

Problem Solved

Imagine you have an AI generation service where users can submit unlimited tasks. Without balanced queuing:

Laravel Balanced Queue solves this by:

How It Works

The Problem

The Solution

Balanced Queue partitions jobs by user and rotates between them:

Strategy Comparison

Round-Robin Strategy (recommended) — strict rotation:

Random Strategy — unpredictable but fast:

Smart Strategy — prioritizes smaller queues:

Concurrency Limiting

With max_concurrent: 2 per partition:

Installation

Publish the configuration:

Quick Start

Step 1: Add Queue Connection

Add to config/queue.php:

Step 2: Create a Job

Step 3: Dispatch Jobs

Step 4: Run Workers

That's it! Jobs are now distributed fairly with max 2 concurrent per user.


Laravel Horizon Integration

Configuration

Add a supervisor for balanced queue in config/horizon.php:

Important: What Works and What Doesn't with Horizon

Feature Status Notes
Job execution Works Jobs execute normally through Horizon workers
Failed jobs list Works Failed jobs appear in Horizon
Worker metrics Works CPU, memory, throughput visible
Pending jobs count Doesn't work Horizon shows 0 pending
Completed jobs list Experimental Enable with horizon.enabled config
Recent jobs list Experimental Enable with horizon.enabled config
horizon:clear Doesn't work Use balanced-queue:clear instead

Why? Balanced Queue uses a different Redis key structure (partitioned queues) than standard Laravel queues. Horizon expects jobs in queues:{name} but we store them in balanced-queue:queues:{name}:{partition}.

Experimental: Horizon Dashboard Integration

You can enable experimental Horizon events integration to see completed/recent jobs in the Horizon dashboard:

Value Behavior
'auto' Enable if laravel/horizon is installed (default)
true Always enable (requires Horizon)
false Disable Horizon events

Or via environment variable:

Warning: This feature is experimental and adds a small overhead per job (writing to Horizon's Redis keys). Test thoroughly in your environment before using in production.

What this enables:

What still doesn't work:

Monitoring Commands

Use built-in commands instead of Horizon for queue management:

Example output of balanced-queue:table --watch:


Configuration

Partition Strategies

Choose how partitions are selected for processing:

Strategy Description Best For
random Random partition selection (Redis SRANDMEMBER) High-load, stateless systems
round-robin Strict sequential: A→B→C→A→B→C Recommended. Fair distribution
smart Considers queue size + wait time, boosts small queues Preventing starvation of small users

Concurrency Limiters

Control how many jobs run simultaneously per partition:

Limiter Description Best For
null No limits, unlimited parallel jobs When you only need fair distribution
simple Fixed limit per partition (e.g., max 2) Recommended. Most use cases
adaptive Dynamic limit based on system load Auto-scaling scenarios

Environment Variables


Partition Keys

Automatic Detection

The BalancedDispatchable trait automatically detects partition key from common property names:

Supported auto-detected properties: $userId, $user_id, $tenantId, $tenant_id

Explicit Partition

Custom Partition Logic

Override getPartitionKey() in your job:

Global Partition Resolver

Set a default resolver in config for all jobs:

Partition Resolution Priority

When determining the partition key, the following order is used:

Priority Method Description
1 onPartition() Explicitly set when dispatching
2 getPartitionKey() Custom method defined in your job class
3 partition_resolver Global resolver from config
4 Auto-detection Properties: userId, user_id, tenantId, tenant_id
5 'default' Fallback partition

The first non-null value wins. This allows you to:


Advanced Usage

Programmatic Metrics

Custom Strategy

Register in config:

Custom Limiter


Redis Structure

Understanding the Redis key structure helps with debugging:

Example with default prefix and queue:

Debugging with Redis CLI


Troubleshooting

Jobs not executing

  1. Check that connection name matches in queue.php and when dispatching:

  2. Verify worker is running with correct connection:

Jobs stuck / not completing

Check for orphaned active job entries:

Horizon shows 0 pending jobs

This is expected behavior. Use balanced-queue:table command instead:

Workers idle but jobs pending

Check if all partitions hit their concurrency limit:

If all partitions show Active = max_concurrent, workers are waiting for slots to free up.


Monitoring with Prometheus & Grafana

The package provides optional HTTP endpoints for monitoring integration.

Enable Monitoring Endpoints

Available Endpoints

Endpoint Format Description
/balanced-queue/metrics Prometheus Metrics in Prometheus text format
/balanced-queue/metrics/json JSON Metrics for Grafana Infinity plugin

Security

By default, endpoints are protected with IP whitelist middleware. Configure allowed IPs in config/balanced-queue.php:

Prometheus Setup

  1. Add scrape config to prometheus.yml:

  2. Available metrics:

Grafana with Infinity Plugin (Real-time without Prometheus)

For real-time monitoring without Prometheus server, use Grafana Infinity datasource:

  1. Install Infinity plugin in Grafana
  2. Create datasource pointing to your app
  3. Use the JSON endpoint:

  4. Configure Infinity datasource query:

    • Type: JSON
    • URL: https://your-app.com/balanced-queue/metrics/json
    • Parser: Backend
  5. For queue summary table: Rows/Root: queues
  6. For partition details: Rows/Root: queues[0].partitions (or use JSONata for all partitions)

Testing


Requirements

Credits

Inspired by aloware/fair-queue with improvements:

License

MIT License. See LICENSE for details.


All versions of laravel-balanced-queue with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/queue Version ^10.0|^11.0|^12.0|^13.0
illuminate/redis Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package yangusik/laravel-balanced-queue contains the following files

Loading the files please wait ...