PHPackages                             solophp/task-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. solophp/task-queue

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

solophp/task-queue
==================

Enhanced PHP task queue using Solo Database with retry mechanism and task expiration support.

v2.1.0(9mo ago)018MITPHPPHP &gt;=8.2

Since Mar 4Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/SoloPHP/Task-Quere)[ Packagist](https://packagist.org/packages/solophp/task-queue)[ RSS](/packages/solophp-task-queue/feed)WikiDiscussions main Synced 1mo ago

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

TaskQueue
=========

[](#taskqueue)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5c77ba80c031b1b46775925511b2d04ec2005826ec472861c0b7e19eeca5b163/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736f6c6f7068702f7461736b2d71756575652e737667)](https://packagist.org/packages/solophp/task-queue)[![License](https://camo.githubusercontent.com/51fd3bec782ff55c9987667426f295535d1c2a3c9562cf657253d5bd3e9a6ae9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f736f6c6f7068702f7461736b2d71756575652e737667)](https://github.com/solophp/task-queue/blob/main/LICENSE)[![PHP Version](https://camo.githubusercontent.com/4649a9327cacbcf62c05dad48867bbedd48bd25accde45fe6b2c250291cef187/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736f6c6f7068702f7461736b2d71756575652e737667)](https://packagist.org/packages/solophp/task-queue)

A lightweight PHP task queue built on top of PDO.
Supports scheduled execution, retries, task expiration, indexed task types, automatic deletion of completed tasks, and optional process-level locking via `LockGuard`.

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

[](#-installation)

```
composer require solophp/task-queue
```

📋 Requirements
--------------

[](#-requirements)

- **PHP**: &gt;= 8.2
- **Extensions**:
    - `ext-json` - for JSON payload handling
    - `ext-pdo` - for database operations
    - `ext-posix` - for LockGuard process locking (optional)

This package uses standard PHP extensions and has minimal external dependencies. No external database libraries required - works with any PDO-compatible database (MySQL, PostgreSQL, SQLite, etc.).

⚙️ Setup
--------

[](#️-setup)

```
use Solo\TaskQueue\TaskQueue;

$pdo = new PDO('mysql:host=localhost;dbname=test', 'username', 'password');
$queue = new TaskQueue($pdo, table: 'tasks', maxRetries: 5, deleteOnSuccess: true);
$queue->install(); // creates the tasks table if not exists
```

🚀 Usage
-------

[](#-usage)

### Add a task:

[](#add-a-task)

```
$taskId = $queue->addTask(
    'email_notification',
    ['type' => 'email_notification', 'user_id' => 123, 'template' => 'welcome'],
    new DateTimeImmutable('tomorrow') // optional, defaults to now
);
```

### Process all tasks:

[](#process-all-tasks)

```
$queue->processPendingTasks(function (string $name, array $payload) {
    match ($name) {
        'email_notification' => sendEmail($payload),
        'push_notification' => sendPush($payload),
        default => throw new RuntimeException("Unknown task: $name")
    };
});
```

### Process only specific type:

[](#process-only-specific-type)

```
$queue->processPendingTasks(function (string $name, array $payload) {
    sendEmail($payload);
}, 20, 'email_notification'); // only tasks where payload_type column = 'email_notification'
```

🔒 Using `LockGuard` (optional)
------------------------------

[](#-using-lockguard-optional)

```
use Solo\TaskQueue\LockGuard;

$lockFile = __DIR__ . '/storage/locks/my_worker.lock';
$lock = new LockGuard($lockFile); // path to lock file

if (!$lock->acquire()) {
    exit(0); // Another worker is already running
}

try {
    $queue->processPendingTasks(...);
} finally {
    $lock->release(); // Optional, auto-released on shutdown
}
```

🧰 Features
----------

[](#-features)

- **Task Retries** – Configurable max retry attempts before marking as failed
- **Task Expiration** – Automatic expiration via `expires_at` timestamp
- **Indexed Task Types** – Fast filtering by `payload_type`
- **Row-Level Locking** – Prevents concurrent execution of the same task
- **Transactional Safety** – All task operations are executed within a transaction
- **Optional Process Locking** – Prevent overlapping workers using `LockGuard`
- **Optional Deletion on Success** – Set `deleteOnSuccess: true` to automatically delete tasks after success

🔗 Integration with Event-Dispatcher
-----------------------------------

[](#-integration-with-event-dispatcher)

TaskQueue implements `TaskQueueInterface` and can be used as an async queue backend for [SoloPHP Event-Dispatcher](https://github.com/SoloPHP/Event-Dispatcher). The Event-Dispatcher library should contain a `TaskQueueAdapter` in its adapter collection that implements the integration.

For async event processing setup, refer to the Event-Dispatcher documentation.

🧪 API Methods
-------------

[](#-api-methods)

MethodDescription`install()`Create the tasks table`addTask(string $name, array $payload, ?DateTimeImmutable $scheduledAt = null, ?DateTimeImmutable $expiresAt = null)`Add task to the queue (default schedule: now)`getPendingTasks(int $limit = 10, ?string $onlyType = null)`Retrieve ready-to-run tasks, optionally filtered by type`markCompleted(int $taskId)`Mark task as completed`markFailed(int $taskId, string $error = '')`Mark task as failed with error message`processPendingTasks(callable $callback, int $limit = 10, ?string $onlyType = null)`Process pending tasks with a custom handler🧪 Testing
---------

[](#-testing)

```
# Run tests
composer test

# Run code sniffer
composer cs

# Fix code style issues
composer cs-fix
```

📄 License
---------

[](#-license)

This project is open-sourced under the [MIT license](./LICENSE).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance57

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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 ~52 days

Total

4

Last Release

283d ago

Major Versions

v1.1.0 → v2.0.02025-08-02

### Community

Maintainers

![](https://www.gravatar.com/avatar/2f29817cec408d033cd4441c8f760e3ae40248dc0f66856a09080d282aee6959?d=identicon)[Vitaliy Olos](/maintainers/Vitaliy%20Olos)

---

Top Contributors

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

---

Tags

phpasyncschedulerqueuejobsTasks

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/solophp-task-queue/health.svg)

```
[![Health](https://phpackages.com/badges/solophp-task-queue/health.svg)](https://phpackages.com/packages/solophp-task-queue)
```

###  Alternatives

[dereuromark/cakephp-queue

The Queue plugin for CakePHP provides deferred task execution.

308850.3k14](/packages/dereuromark-cakephp-queue)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)[microsoft/azure-storage-queue

This project provides a set of PHP client libraries that make it easy to access Microsoft Azure Storage Queue APIs.

142.6M17](/packages/microsoft-azure-storage-queue)

PHPackages © 2026

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