nixphp / queue
NixPHP Queue Plugin for asynchronous jobs.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:nixphp-plugin
pkg:composer/nixphp/queue
Requires
- php: >=8.3
- ext-pdo: *
- nixphp/cli: ^0.1.0
- nixphp/framework: ^0.1.0
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
- phpunit/phpunit: ^12.1
This package is auto-updated.
Last update: 2025-12-11 22:40:11 UTC
README
nixphp/queue
Minimalistic queueing for NixPHP β file-based, simple, and extendable.
This plugin provides a lightweight job queue system with CLI worker support and no external dependencies by default.
π§© Part of the official NixPHP plugin collection. Use it when you want to delay tasks, run background jobs, or decouple logic β without setting up Redis or RabbitMQ.
π¦ Features
- β File-based queue driver (no DB or Redis required)
- β CLI worker for background processing
- β
One-off async execution (
pushAndRun()) - β Deadletter handling and retry support
- β Fully PSR-4 and event-loop friendly
- β Extendable: write your own driver for SQLite, Redis, etc.
π₯ Installation
composer require nixphp/queue
Thatβs it. The plugin will be autoloaded automatically.
π Usage
β Queue a job
Create a job class that implements the QueueJobInterface:
use NixPHP\Queue\QueueJobInterface; class SendWelcomeEmail implements QueueJobInterface { public function __construct(protected array $payload) {} public function execute(): void { // Send your email here } }
Push it to the queue:
queue()->push(SendWelcomeEmail::class, ['email' => 'user@example.com']);
β‘ Fire-and-forget (async)
For one-off asynchronous execution, use:
queue()->pushAndRun(SendWelcomeEmail::class, ['email' => 'user@example.com']);
This queues the job and immediately runs it in the background via a short-lived CLI process.
Great for use cases like emails, logging, or notifications, without blocking the current request.
π§΅ Start the worker
Run the CLI worker to process jobs continuously:
./bin/nix queue:worker
Run a single job only:
./bin/nix queue:worker --once
πΉ
--onceis also used internally bypushAndRun()for async dispatching.
π₯ Deadletter & Retry
Failed jobs are automatically written to the deadletter folder (only for FileDriver).
You can retry failed jobs via:
./bin/nix queue:retry-failed
By default, retried jobs are removed from the deadletter queue.
Use --keep to retain them:
./bin/nix queue:retry-failed --keep
π§ Drivers
The queue system is driver-based. Included drivers:
| Driver | Description | Suitable for |
|---|---|---|
FileQueue |
Stores jobs as .job files in a folder |
Local use, no DB needed |
SQLiteQueue |
Stores jobs in SQLite table | Shared memory across requests |
To change the driver, register it manually:
use NixPHP\Queue\Core\Queue; use NixPHP\Queue\Drivers\FileDriver; app()->set(Queue::class, static fn() => new Queue( new FileDriver( __DIR__ . FileDriver::DEFAULT_QUEUE_PATH, __DIR__ . FileDriver::DEFAULT_DEADLETTER_PATH ) ));
π The file path is only relevant for
FileDriver.
π οΈ Supervisor example (optional)
To run the worker persistently in production, use Supervisor:
[program:nixphp-worker] command=php bin/nix queue:worker directory=/path/to/your/app autostart=true autorestart=true stderr_logfile=/var/log/nixphp/worker.err.log stdout_logfile=/var/log/nixphp/worker.out.log
β Requirements
nixphp/framework^0.1.0nixphp/cli^0.1.0 (required for worker commands)
π License
MIT License.