PHPackages                             fahriar/laravel-shared-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. fahriar/laravel-shared-queue

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

fahriar/laravel-shared-queue
============================

A robust, shared-hosting-friendly async queue system for Laravel applications.

v1.0.0(1mo ago)02↑2900%MITPHPPHP ^8.1

Since Apr 5Pushed 1mo agoCompare

[ Source](https://github.com/Fahriar-Ahammed/laravel-shared-queue)[ Packagist](https://packagist.org/packages/fahriar/laravel-shared-queue)[ RSS](/packages/fahriar-laravel-shared-queue/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

Laravel Shared Queue
====================

[](#laravel-shared-queue)

[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

A robust, shared-hosting-friendly asynchronous task runner for Laravel.

This package provides a **database-backed, cron-driven, retryable, idempotent async task system**. It is specifically architected for environments where traditional queue workers (like Supervisor + `php artisan queue:work` or Redis/Horizon) cannot run continuously. Perfect for cPanel, DirectAdmin, or strictly restricted shared hosting setups.

---

🚀 When to use this package
--------------------------

[](#-when-to-use-this-package)

- You are on a shared host with strict background process limits and no daemonizing tools like Supervisor.
- You only have Cron access.
- You want a lightweight database-first queue with absolutely zero extra infrastructure or Redis required.

⚠️ When NOT to use this package
-------------------------------

[](#️-when-not-to-use-this-package)

- You need true sub-second real-time processing (use Redis/Beanstalkd instead).
- You have heavy, long-running CPU-bound tasks like video encoding or FFmpeg.
- You are already using Laravel Horizon successfully.

---

📦 Installation
--------------

[](#-installation)

Require the package via composer:

```
composer require fahriar/laravel-shared-queue
```

Publish the configuration file and database migrations:

```
php artisan vendor:publish --tag=shared-queue-config
php artisan vendor:publish --tag=shared-queue-migrations
```

Run the database migrations to create the `shared_queue_tasks` table:

```
php artisan migrate
```

---

🛠️ Setup &amp; Configuration
----------------------------

[](#️-setup--configuration)

Define your tasks inside `config/shared-queue.php`. Here you map simple string types to concrete classes:

```
'tasks' => [
    'send_invoice_email' => \App\Tasks\SendInvoiceEmailTask::class,
    'process_payment'    => \App\Tasks\ProcessPaymentTask::class,
],
```

### Create a Task Handler

[](#create-a-task-handler)

Your handlers must implement the `LaravelSharedQueue\Contracts\TaskHandler` contract. It natively supports Laravel's Container, so dependency injection in the constructor works perfectly:

```
namespace App\Tasks;

use LaravelSharedQueue\Contracts\TaskHandler;
use Illuminate\Support\Facades\Log;

class SendInvoiceEmailTask implements TaskHandler
{
    public function handle(array $payload): void
    {
        // Business logic here.
        Log::info("Sending email for invoice: " . $payload['invoice_id']);
    }
}
```

Keep your task handlers idempotent and bite-sized. Let the database act as the state engine!

---

⚡ Dispatching Tasks
-------------------

[](#-dispatching-tasks)

You can dispatch tasks seamlessly using the injected Facade or the global helper function.

### Basic Dispatch

[](#basic-dispatch)

```
use LaravelSharedQueue\Facades\SharedQueue;

SharedQueue::dispatch('send_invoice_email', [
    'invoice_id' => 1001,
]);

// Or securely dispatch using the global helper:
shared_queue('send_invoice_email', ['invoice_id' => 1001]);
```

### Delayed Tasks

[](#delayed-tasks)

Need to process something in the future? Pass an explicit delay:

```
SharedQueue::dispatch('send_invoice_email', ['invoice_id' => 1001], [
    'delay' => now()->addMinutes(10) // Also accepts integer seconds
]);
```

### Idempotency (Prevent Duplicate Jobs)

[](#idempotency-prevent-duplicate-jobs)

If you operate in high-traffic or looping scripts, protect against identical tasks firing simultaneously:

```
SharedQueue::dispatch('process_payment', ['order_id' => 5], [
    'idempotency_key' => 'payment_order_5'
]);
```

*If a `pending` or `processing` task already exists with this key, the dispatch safely ignores the request to avoid duplicates.*

### Dispatch After Database Commit

[](#dispatch-after-database-commit)

Only dispatch the task if the outer database transaction officially commits:

```
SharedQueue::dispatchAfterCommit('send_invoice_email', ['invoice_id' => 1001]);
```

*This safely waits until the active DB transaction commits before finally inserting the task queue row.*

---

⚙️ Running the Worker
---------------------

[](#️-running-the-worker)

Since this is built explicitly for shared hosting systems, you run the queue worker natively via Laravel's scheduled cron job engine.

In your `routes/console.php` (Laravel 11+) or `app/Console/Kernel.php` (Laravel 10):

```
use Illuminate\Support\Facades\Schedule;

Schedule::command('shared-queue:work')->everyMinute()->withoutOverlapping();
```

Make sure your server/cPanel cron is set to trigger your application schedule every minute natively:

```
* * * * * cd /home/youruser/public_html && php artisan schedule:run >> /dev/null 2>&1
```

Once running, the worker runs batch checks and operates securely utilizing robust database row-locking tools (`skipLocked() / lockForUpdate()`) to ensure no race conditions overlap.

---

🧰 Managing Tasks (CLI)
----------------------

[](#-managing-tasks-cli)

The package provides a suite of helpful Artisan commands to inspect your queue:

```
# View all recent tasks in a neat table representation
php artisan shared-queue:list

# Retry a specifically failed or dead task
php artisan shared-queue:retry {id}

# Retry all failed/dead tasks simultaneously
php artisan shared-queue:retry --all-dead

# Delete old successfully "completed" tasks (clears out database bloat)
php artisan shared-queue:prune

# Completely wipe tasks marked permanently as "dead"
php artisan shared-queue:flush-dead
```

---

🧪 Testing (For Contributors)
----------------------------

[](#-testing-for-contributors)

To run the internal unit and feature test suite ensuring 100% stable compatibility:

```
composer run test
# OR
./vendor/bin/phpunit
```

🔒 Security Vulnerabilities
--------------------------

[](#-security-vulnerabilities)

If you discover a security vulnerability within this package, please e-mail Fahriar Ahammed via . All security vulnerabilities will be promptly addressed.

📝 License
---------

[](#-license)

The Laravel Shared Queue package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance90

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

Unknown

Total

1

Last Release

46d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/61075766?v=4)[Fahriar Ahammed](/maintainers/Fahriar-Ahammed)[@Fahriar-Ahammed](https://github.com/Fahriar-Ahammed)

---

Top Contributors

[![Fahriar-Ahammed](https://avatars.githubusercontent.com/u/61075766?v=4)](https://github.com/Fahriar-Ahammed "Fahriar-Ahammed (1 commits)")

---

Tags

asynclaravelqueuecronshared hostingdatabase-queue

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fahriar-laravel-shared-queue/health.svg)

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

###  Alternatives

[harris21/laravel-fuse

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

3786.5k](/packages/harris21-laravel-fuse)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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