PHPackages                             raicem/laravel-defer-jobs - 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. raicem/laravel-defer-jobs

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

raicem/laravel-defer-jobs
=========================

Defer your jobs to be executed after the response is sent. Without a queue system.

1.0.2(6y ago)31.0kMITPHPPHP ^7.2

Since Jun 17Pushed 6y agoCompare

[ Source](https://github.com/raicem/laravel-defer-jobs)[ Packagist](https://packagist.org/packages/raicem/laravel-defer-jobs)[ Docs](https://github.com/raicem/laravel-defer-jobs)[ RSS](/packages/raicem-laravel-defer-jobs/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Laravel Defer Jobs
------------------

[](#laravel-defer-jobs)

Defer your jobs to be executed after the response is sent\*. Without a queue system.

\*Only if you are using `php-fpm`. See requirements section for more info.

### Why

[](#why)

Sometimes you don't want to setup a queue system just to do some light work outside of the request and response cycle. This package is created to show it is possible to extract some work out of the request and response cycle without using a queue system. Please note, this is more of a proof of concept and I believe there can be more robust implementations.

### How

[](#how)

`php-fpm` exposes a function called [fastcgi\_finish\_request](https://www.php.net/manual/en/function.fastcgi-finish-request.php) which is used by Laravel to send the request to the webserver.

Laravel exposes a method called `terminate` in the middlewares that allows you to do some work after `fastcgi_finish_request` function is called. This package is basically just a service that collects jobs to be deferrered and runs them in the `terminate` function in a [middleware](https://laravel.com/docs/5.8/middleware#terminable-middleware).

### Installation

[](#installation)

Install package using composer

```
composer require raicem/laravel-defer-jobs
```

This package support [auto discovery](https://laravel-news.com/package-auto-discovery). So the service provider should be registered automatically.

You have to register the middleware manually. You can register it in the `app/Http/Kernel.php` file.

```
// app/Http/Kernel.php
 protected $middleware = [
     //..
    \App\Http\Middleware\TrustProxies::class,
    \Raicem\Defer\Middleware\ExecuteDeferredJobs::class,
];
```

Then you are ready to go.

### Usage

[](#usage)

This package leverages Laravel's job implementation. Jobs are objects to be sent to the [queue system](https://laravel.com/docs/5.8/queues).

First you can [create a job](https://laravel.com/docs/5.8/queues#creating-jobs).

```
php artisan make:job LogSomething
```

In your job class implement the `Deferrable` trait.

```
use Raicem\Defer\Deferrable;

class LogSomething implements ShouldQueue
{
    use Deferrable, SerializesModels;

    private $message;

    public function __construct(string $message)
    {
        $this->message = $message;
    }

    public function handle()
    {
        // handle job
    }
}
```

Now you can call the job anywhere you want. For example in your controller.

```
// HomeController.php

use App\Jobs\LogSomething;

class HomeController
{
    public function action()
    {
        // do stuff
        LogSomething::defer('my log message');

        return view('welcome');
    }
}
```

Your job will be executed after the response is sent.

Please note this package does not have any relation with the queue system. You can still create a job and send it to the proper [queue system](https://laravel.com/docs/5.8/queues).

Using job objects will allow you the switch implementations later down the line. If you no longer want to defer jobs and want to send them to the queue system, it very simple.

### Use cases

[](#use-cases)

- Sending emails
- Logging
- Gathering analytics data from request or response
- Making API calls

Basically, some light work that would slow your response times.

### Requirements

[](#requirements)

This package will only do its effect if you are using `php-fpm` to execute your code. If you don't use `php-fpm` and still try to use it, it will have no effect and it will run the jobs before the response is sent.

### Warning

[](#warning)

Please note that, if you want to do heavy work using this method, this package is not very suitable for you. `php-fpm` will keep the process open until your script ends. By doing so you may hit the maximum limit of the child processes of `php-fpm`. If you hit that limit, you may not receive any new requests.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

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

2521d ago

### Community

Maintainers

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

---

Top Contributors

[![raicem](https://avatars.githubusercontent.com/u/10389957?v=4)](https://github.com/raicem "raicem (7 commits)")

---

Tags

laravelqueuedeferring

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/raicem-laravel-defer-jobs/health.svg)

```
[![Health](https://phpackages.com/badges/raicem-laravel-defer-jobs/health.svg)](https://phpackages.com/packages/raicem-laravel-defer-jobs)
```

###  Alternatives

[harris21/laravel-fuse

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

3786.5k](/packages/harris21-laravel-fuse)[pmatseykanets/artisan-beans

Easily manage your Beanstalkd job queues right from the Laravel artisan command

4482.1k](/packages/pmatseykanets-artisan-beans)

PHPackages © 2026

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