nixphp / queue
NixPHP Queue Plugin for asynchronous jobs.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:nixphp-plugin
Requires
- php: >=8.3
- nixphp/cli: dev-main
- nixphp/database: dev-main
- nixphp/framework: dev-main
Requires (Dev)
- phpunit/php-code-coverage: ^12.1
- phpunit/phpunit: ^12.1
This package is auto-updated.
Last update: 2025-07-29 22:30:16 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 handle(): 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
πΉ
--once
is 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\Queue; use NixPHP\Queue\Drivers\FileQueue; app()->set('queue', fn() => new Queue( new FileQueue(__DIR__ . '/storage/queue', __DIR__ . '/storage/queue/deadletter') ));
π 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
>= 1.0nixphp/cli
(required for worker commands)
π License
MIT License.