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.
- ✅ 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.
composer require nixphp/queueThat’s it. The plugin will be autoloaded automatically.
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']);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.
Run the CLI worker to process jobs continuously:
./bin/nix queue:workerRun a single job only:
./bin/nix queue:worker --once🔹
--onceis also used internally bypushAndRun()for async dispatching.
Failed jobs are automatically written to the deadletter folder (only for FileDriver).
You can retry failed jobs via:
./bin/nix queue:retry-failedBy default, retried jobs are removed from the deadletter queue.
Use --keep to retain them:
./bin/nix queue:retry-failed --keepThe 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.
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.lognixphp/framework>= 1.0nixphp/cli(required for worker commands)
MIT License.
