PHPackages                             timmylindh/laravel-batch-dispatcher - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. timmylindh/laravel-batch-dispatcher

ActiveLibrary[Queues &amp; Workers](/categories/queues)

timmylindh/laravel-batch-dispatcher
===================================

Batch Laravel queued jobs and queued event listeners into a single queued job dispatched at the end of the request.

v0.0.2(8mo ago)120MITPHPPHP ^8.1||^8.2||^8.3CI passing

Since Aug 30Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/timmylindh/laravel-batch-dispatcher)[ Packagist](https://packagist.org/packages/timmylindh/laravel-batch-dispatcher)[ Docs](https://github.com/timmylindh/laravel-batch-dispatcher)[ GitHub Sponsors]()[ RSS](/packages/timmylindh-laravel-batch-dispatcher/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (10)Versions (4)Used By (0)

laravel-batch-dispatcher
========================

[](#laravel-batch-dispatcher)

[![Latest Version on Packagist](https://camo.githubusercontent.com/c9b5d220c915443ee4c75854176ffa152f18193667efced26fd2231c7a248110/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696d6d796c696e64682f6c61726176656c2d62617463682d646973706174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/timmylindh/laravel-batch-dispatcher)[![GitHub Tests Action Status](https://camo.githubusercontent.com/87f6af508d57e3854c67fd15b9733ab7371131a953ae8699b5fc1a0c5853e9b5/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f74696d6d796c696e64682f6c61726176656c2d62617463682d646973706174636865722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/timmylindh/laravel-batch-dispatcher/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/da6de251436a49664f8febc1c6b0fba29538236f2af43b56e7603598d89a1869/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f74696d6d796c696e64682f6c61726176656c2d62617463682d646973706174636865722f636865636b2d636f64652d666f726d617474696e672e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/timmylindh/laravel-batch-dispatcher/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/cb4dc321681f8ff29659686bb261af3d9966e0b05cd43caf6c1adee30b1f089a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696d6d796c696e64682f6c61726176656c2d62617463682d646973706174636865722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/timmylindh/laravel-batch-dispatcher)

Batch queued jobs and queued event listeners into a single queued job. This reduces the number of queue requests by capturing multiple dispatches and sending them as one job that processes all items.

Installation
------------

[](#installation)

Requires:

- Laravel &gt;= 10
- PHP &gt;= 8.1

You can install the package via composer:

```
composer require timmylindh/laravel-batch-dispatcher
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-batch-dispatcher-config"
```

Usage
-----

[](#usage)

### Behavior

[](#behavior)

- All calls to `dispatch()`, `SomeJob::dispatch()`, and `Event::dispatch()` will be buffered during the request.
- On terminate, the package queues a single wrapper job which in turn dispatches all buffered jobs and queued listeners.

Configuration
-------------

[](#configuration)

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-batch-dispatcher-config"
```

The batching behavior is controlled by `config/batch-dispatcher.php`:

```
return [
  "enabled" => env("BATCH_DISPATCHER_ENABLED", true),

  /**
   * In testing, avoid serializing jobs and run the wrapper immediately for assertions
   */
  "synchronous_testing" => env(
    "BATCH_DISPATCHER_SYNC_TESTING",
    env("APP_ENV") === "testing"
  ),

  /**
   * Maximum number of buffered items (jobs + queued listeners)
   * per wrapper job. When exceeded, multiple wrapper jobs will be dispatched.
   */
  "max_batch_size" => env("BATCH_DISPATCHER_MAX_SIZE", 10),

  /**
   * Enable the middleware to batch the requests.
   * Otherwise you will have to manually wrap the routes in the middleware.
   */
  "enable_middleware" => env("BATCH_DISPATCHER_ENABLE_MIDDLEWARE", true),
];
```

### Middleware

[](#middleware)

Setting `enable_middleware = true` will automatically apply the batching to the `api` and `web` middleware groups. You can apply the batching to specific routes or groups by adding the `BatchRequests` middleware.

### Notes

[](#notes)

- Only instances of jobs implementing `ShouldQueue` and queued event listeners are batched.
- Per-job queue options (connection/queue/delay) are respected when listeners are enqueued by the wrapper. Jobs are dispatched as usual by the wrapper.

How it works
------------

[](#how-it-works)

During the request, we intercept:

- Bus dispatches of `ShouldQueue` jobs and store the job instances in memory
- Event dispatches with queued listeners and capture their queued calls

On terminate, a single `ProcessBatch` job is queued. It then dispatches the buffered jobs and enqueues/invokes listeners.

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Timmy Lindholm](https://github.com/timmylindh)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance60

Regular maintenance activity

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

255d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/afd9f241fb02dad8f6806c2d445c54498bdb6841c7cce16d1fa9ba0ce4572167?d=identicon)[timmylindh](/maintainers/timmylindh)

---

Top Contributors

[![timmylindh](https://avatars.githubusercontent.com/u/74464421?v=4)](https://github.com/timmylindh "timmylindh (11 commits)")

---

Tags

laravelperformanceeventsqueuebatchjobsdispatcherBatching

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/timmylindh-laravel-batch-dispatcher/health.svg)

```
[![Health](https://phpackages.com/badges/timmylindh-laravel-batch-dispatcher/health.svg)](https://phpackages.com/packages/timmylindh-laravel-batch-dispatcher)
```

###  Alternatives

[laravel/scout

Laravel Scout provides a driver based solution to searching your Eloquent models.

1.7k49.4M479](/packages/laravel-scout)[laravel/pulse

Laravel Pulse is a real-time application performance monitoring tool and dashboard for your Laravel application.

1.7k12.1M99](/packages/laravel-pulse)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[harris21/laravel-fuse

Circuit breaker for Laravel queue jobs. Protect your workers from cascading failures.

3786.5k](/packages/harris21-laravel-fuse)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[croustibat/filament-jobs-monitor

Background Jobs monitoring like Horizon for all drivers for FilamentPHP

254255.2k6](/packages/croustibat-filament-jobs-monitor)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
