PHPackages                             telkins/laravel-job-funneling-middleware - 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. [Caching](/categories/caching)
4. /
5. telkins/laravel-job-funneling-middleware

ActiveLibrary[Caching](/categories/caching)

telkins/laravel-job-funneling-middleware
========================================

A middleware that can funnel jobs.

v0.4.0(4y ago)54.6k2MITPHPPHP ^7.3|^8.0CI failing

Since Dec 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/telkins/laravel-job-funneling-middleware)[ Packagist](https://packagist.org/packages/telkins/laravel-job-funneling-middleware)[ Docs](https://github.com/telkins/laravel-job-funneling-middleware)[ RSS](/packages/telkins-laravel-job-funneling-middleware/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (4)Versions (6)Used By (0)

A job middleware to funnel jobs
===============================

[](#a-job-middleware-to-funnel-jobs)

[![Latest Version on Packagist](https://camo.githubusercontent.com/bd8d0ac40373d48100812ba9998e11ad7d5df8f2cef3a33761657fed2754ae57/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74656c6b696e732f6c61726176656c2d6a6f622d66756e6e656c696e672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/telkins/laravel-job-funneling-middleware)[![Build Status](https://camo.githubusercontent.com/607785bede28a28c7a4cd2204db1dd49828bff0e24f877c17ca2e21383750e9f/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f74656c6b696e732f6c61726176656c2d6a6f622d66756e6e656c696e672d6d6964646c65776172652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/telkins/laravel-job-funneling-middleware)[![Quality Score](https://camo.githubusercontent.com/1f5a833d23d0be936ebaef0b06f466b8accb75cbd717a84e94d84254958ba9a1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f74656c6b696e732f6c61726176656c2d6a6f622d66756e6e656c696e672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/telkins/laravel-job-funneling-middleware)[![StyleCI](https://camo.githubusercontent.com/6efea85cdd10ae0f15385ecdbb139422ad2619f7f189794974148a58cf6838f5/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3231313536313730352f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/211561705)[![Total Downloads](https://camo.githubusercontent.com/4bdf2ce55856b56acb8f88da1f4ce527bcaf0de9657e7310c76e29105c83824c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74656c6b696e732f6c61726176656c2d6a6f622d66756e6e656c696e672d6d6964646c65776172652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/telkins/laravel-job-funneling-middleware)

This package contains a [job middleware](https://laravel.com/docs/master/queues#job-middleware) that can funnel jobs in Laravel apps.

Special Credits
---------------

[](#special-credits)

Permission was granted by [Freek Van der Herten](https://github.com/freekmurze) to copy Spatie's [laravel-rate-limited-job-middleware](https://github.com/spatie/laravel-rate-limited-job-middleware), rename it, and maintain it on my own. As such, the vast bulk of this package is built on theirs. Thanks...! :-)

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

[](#installation)

You can install the package via composer:

```
composer require telkins/laravel-job-funneling-middleware
```

This package requires Redis to be set up in your Laravel app.

Usage
-----

[](#usage)

By default, the middleware will only allow 1 job to be executed at a time. Any jobs that are not allowed will be released for 5 seconds.

To apply the middleware just add the `Telkins\JobFunnelingMiddleware\Funneled` to the middlewares of your job.

```
namespace App\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Telkins\JobFunnelingMiddleware\Funneled;

class TestJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable;

    public function handle()
    {
        // your job logic
    }

    public function middleware()
    {
        return [new Funneled()];
    }
}
```

### Configuring attempts

[](#configuring-attempts)

When using rate limiting, including funneling, the number of attempts of your job may be hard to predict. Instead of using a fixed number of attempts, it's better to use [time based attempts](https://laravel.com/docs/master/queues#time-based-attempts).

You can add this to your job class:

```
/*
 * Determine the time at which the job should timeout.
 *
 */
public function retryUntil() :  \DateTime
{
    return now()->addDay();
}
```

### Customizing the behavior

[](#customizing-the-behavior)

You can customize all the behavior. Here's an example where the middleware allows a maximum of 3 jobs to be performed at a time. Jobs that are not allowed will be released for 90 seconds.

```
// in your job

public function middleware()
{
    $funneledMiddleware = (new Funneled())
        ->limit(3)
        ->releaseAfterSeconds(90);

    return [$funneledMiddleware];
}
```

### Customizing Redis

[](#customizing-redis)

By default, the middleware will use the default Redis connection.

The default key that will be used in redis will be the name of the class that created the instance of the middleware. In most cases this will be name of the job in which the middleware is applied. If this is not what you expect, you can use the `key` method to customize it.

Here's an example where a custom connection and custom key is used.

```
// in your job

public function middleware()
{
    $funneledMiddleware = (new Funneled())
        ->connection('my-custom-connection')
        ->key('my-custom-key');

    return [$funneledMiddleware];
}
```

### Conditionally applying the middleware

[](#conditionally-applying-the-middleware)

If you want to conditionally apply the middleware you can use the `enabled` method. It accepts a boolean that determines if the middleware should funnel your job or not.

You can also pass a `Closure` to `enabled`. If it evaluates to a truthy value the middleware will be enabled.

Here's a silly example where the funneling is only activated in January.

```
// in your job

public function middleware()
{
    $shouldFunnelJobs = Carbon::now()->month === 1;

    $funneledMiddleware = (new Funneled())
        ->enabled($shouldFunnelJobs);

    return [$funneledMiddleware];
}
```

### Available methods.

[](#available-methods)

These methods are available to be called on the middleware. Their names should be self-explanatory.

- `limit(int $limitedNumberOfJobs)`
- `releaseAfterOneSecond()`
- `releaseAfterSeconds(int $releaseInSeconds)`
- `releaseAfterOneMinute()`
- `releaseAfterMinutes(int $releaseInMinutes)`
- `releaseAfterRandomSeconds(int $min = 1, int $max = 10)`

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Travis Elkins](https://github.com/telkins)
- [All Contributors](../../contributors)

This code is heavily based on [the funneling example](https://laravel.com/docs/master/queues#job-middleware) found in the Laravel docs.

License
-------

[](#license)

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

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.7% 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 ~217 days

Total

5

Last Release

1469d ago

PHP version history (2 changes)v0.0.1PHP ^7.3

v0.3.0PHP ^7.3|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/d0099a02e09e4fd03c5aca40dd7cc943391d0333009959c276321e59f6423965?d=identicon)[travis.elkins](/maintainers/travis.elkins)

---

Top Contributors

[![telkins](https://avatars.githubusercontent.com/u/53731?v=4)](https://github.com/telkins "telkins (12 commits)")[![josiasmontag](https://avatars.githubusercontent.com/u/1945577?v=4)](https://github.com/josiasmontag "josiasmontag (2 commits)")

---

Tags

funnelhacktoberfestjoblaravelmiddlewarephpqueueredislaravel-job-funneling-middleware

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/telkins-laravel-job-funneling-middleware/health.svg)

```
[![Health](https://phpackages.com/badges/telkins-laravel-job-funneling-middleware/health.svg)](https://phpackages.com/packages/telkins-laravel-job-funneling-middleware)
```

###  Alternatives

[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[namoshek/laravel-redis-sentinel

An extension of Laravels Redis driver which supports connecting to a Redis master through Redis Sentinel.

38679.0k](/packages/namoshek-laravel-redis-sentinel)[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

786.4k](/packages/yangusik-laravel-balanced-queue)[vetruvet/laravel-phpredis

Use phpredis as the redis connection in Laravel

43123.7k](/packages/vetruvet-laravel-phpredis)[ginnerpeace/laravel-redis-lock

Simple redis distributed locks for Laravel.

15114.4k](/packages/ginnerpeace-laravel-redis-lock)[huangdijia/laravel-redis-ide-helper

Redis ide-helper for Laravel.

1243.3k](/packages/huangdijia-laravel-redis-ide-helper)

PHPackages © 2026

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