PHPackages                             nadirabbas/laravel-transaction-commit-queue - 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. nadirabbas/laravel-transaction-commit-queue

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

nadirabbas/laravel-transaction-commit-queue
===========================================

A Laravel queue connector to process jobs after successful transactions commits

01PHP

Since Sep 24Pushed 3y agoCompare

[ Source](https://github.com/nadirabbas/laravel-transaction-commit-queue)[ Packagist](https://packagist.org/packages/nadirabbas/laravel-transaction-commit-queue)[ RSS](/packages/nadirabbas-laravel-transaction-commit-queue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Transaction Commit Queue
================================

[](#laravel-transaction-commit-queue)

A Laravel queue connector to process jobs on successful database transactions commits.

This connector is very similar to the "sync" connector with the difference that jobs are executed after the database transaction has been committed instead of instantly.

It is useful for example when sending notifications that cause that other processes or third party applications read data from your database. When using database transactions and sending notifications, with another queue connectors there is no guarantee that this processes or third parties will find the data as you have set it when you sent the notification as the transaction might not has been committed yet. With this connector, the notifications will be sent on transaction commit event when the database transaction level reaches "0".

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

With Composer installed, you can then install the extension using the following commands:

```
$ php composer.phar require jlorente/laravel-transaction-commit-queue
```

or add

```
...
    "require": {
        "jlorente/laravel-transaction-commit-queue": "*"
    }
```

to the `require` section of your `composer.json` file.

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

[](#configuration)

Register the ServiceProvider in your config/app.php service provider list.

config/app.php

```
return [
    //other stuff
    'providers' => [
        //other stuff
        Jlorente\Laravel\Queue\TransactionCommit\TransactionCommitQueueServiceProvider::class,
    ];
];
```

Then add the driver to the application config queue file.

config\\queue.php

```
return [
    //other stuff
    'connections' => [
        //other stuff
        'transaction-commit' => [
            'driver' => 'transaction-commit',
        ],
    ],
];
```

And publish the configuration file.

```
$ php artisan vendor:publish --provider='Jlorente\Laravel\Queue\TransactionCommit\TransactionCommitQueueServiceProvider'
```

Usage
-----

[](#usage)

See the [Laravel documentation](https://laravel.com/docs/master/queues) to learn how to use jobs and queues.

The basic usage of this queue is like in the following example.

```
DB::transaction(function() {
    // Do something

    dispatch(function() use ($model) {
        $model->notify();
    })->onConnection('transaction-commit');
});
```

Here, the job specified as callback will be delayed until the transaction is committed.

### Dispatching jobs on nested transactions

[](#dispatching-jobs-on-nested-transactions)

You can dispatch jobs to this queue inside nested transactions and the jobs will be processed after all the transactions have been resolved and the commit has been perfomed into the database.

```
class ProcessExample {
    public function run() {
        DB::transaction(function() {
            // Do something more

            $this->nestedRun();
        });
    }

    public function nestedRun() {
        DB::transaction(function() {
            $model = new NotifiableExampleModel();

            // This job will be fired when all the transactions have been commited.
            dispatch(function() use ($model) {
                $model->notify();
            })->onConnection('transaction-commit');
        });
    }
}

$command = new ProcessExample();
$command->run();
```

In this example, the job is dispatched on the transaction created on nestedRun method, but this method is called by the run method from inside another transaction. The execution of the $model-&gt;notify() callback will be delayed until all the transactions have been committed.

### Multiple database connections

[](#multiple-database-connections)

The queue driver will use the connection names defined in the database config file in order to create different queues for each connection.

If you don't specify the queue where to dispatch the job, the default queue will be used and the queue will be processed when the default connection reaches the transaction level of 0.

If you want to init a transaction in other database connection than the default one, remember to specify the queue with the connection name on the dispatched jobs to the transaction-commit-queue like in the following example.

```
DB::connection('other-connection')->transaction(function() {
    // Do something
    $model = new NotifiableExampleModel();

    dispatch(function() use ($model) {
        $model->notify();
    })->onConnection('transaction-commit')->onQueue('other-connection');
});
```

### Testing

[](#testing)

If you use a transaction rollback strategy for testing against the datatabase, you can set the environment variable TRANSACTION\_COMMIT\_DISPATCH\_INSTANTLY in order to dispatch the jobs instantly instead of on transaction commit.

Further Considerations
----------------------

[](#further-considerations)

If there isn't any open transaction on the database connection, the job with be fired instantly.

If a transaction is rolled back, all the pending jobs of the rolled back connection will be discarded.

Remember that [notifications](https://laravel.com/docs/master/notifications) can also be enqueued.

License
-------

[](#license)

Copyright © 2020 José Lorente Martín .

Licensed under the BSD 3-Clause License. See LICENSE.txt for details.

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![jlorente](https://avatars.githubusercontent.com/u/301741?v=4)](https://github.com/jlorente "jlorente (12 commits)")[![nadirabbas](https://avatars.githubusercontent.com/u/38838675?v=4)](https://github.com/nadirabbas "nadirabbas (2 commits)")

### Embed Badge

![Health badge](/badges/nadirabbas-laravel-transaction-commit-queue/health.svg)

```
[![Health](https://phpackages.com/badges/nadirabbas-laravel-transaction-commit-queue/health.svg)](https://phpackages.com/packages/nadirabbas-laravel-transaction-commit-queue)
```

###  Alternatives

[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[amphp/parser

A generator parser to make streaming parsers simple.

14952.8M16](/packages/amphp-parser)[amphp/serialization

Serialization tools for IPC and data storage in PHP.

13451.1M18](/packages/amphp-serialization)[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[deliciousbrains/wp-background-processing

WP Background Processing can be used to fire off non-blocking asynchronous requests or as a background processing tool, allowing you to queue tasks.

1.1k409.8k6](/packages/deliciousbrains-wp-background-processing)[react/async

Async utilities and fibers for ReactPHP

2238.8M171](/packages/react-async)

PHPackages © 2026

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