Download the PHP package solophp/task-queue without Composer
On this page you can find all versions of the php package solophp/task-queue. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package task-queue
TaskQueue
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
๐ Requirements
- PHP: >= 8.2
- Extensions:
ext-json
- for JSON payload handlingext-pdo
- for database operationsext-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
๐ Usage
Add a task:
Process all tasks:
Process only specific type:
๐ Using LockGuard
(optional)
๐งฐ 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
TaskQueue implements TaskQueueInterface
and can be used as an async queue backend for 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
Method | Description |
---|---|
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
๐ License
This project is open-sourced under the MIT license.
All versions of task-queue with dependencies
ext-json Version *
ext-pdo Version *
ext-posix Version *