Queues
Marko’s queue system lets you defer work to background processes. Jobs are dispatched through QueueInterface and processed by a worker, with pluggable backends for different environments.
# Database-backed queuecomposer require marko/queue marko/queue-database
# RabbitMQ queuecomposer require marko/queue marko/queue-rabbitmqCreating Jobs
Section titled “Creating Jobs”<?php
declare(strict_types=1);
namespace App\Blog\Job;
use Marko\Queue\JobInterface;
class SendWelcomeEmail implements JobInterface{ public function __construct( private readonly string $email, private readonly string $name, ) {}
public function handle(): void { // Send the email — this runs in the background }}Dispatching Jobs
Section titled “Dispatching Jobs”<?php
declare(strict_types=1);
use Marko\Queue\QueueInterface;use App\Blog\Job\SendWelcomeEmail;
class RegistrationService{ public function __construct( private readonly QueueInterface $queue, ) {}
public function register(string $email, string $name): void { // ... create user
$this->queue->push(new SendWelcomeEmail( email: $email, name: $name, )); }}Processing Jobs
Section titled “Processing Jobs”marko queue:workAvailable Backends
Section titled “Available Backends”| Package | Backend | Best For |
|---|---|---|
marko/queue-sync | Synchronous (inline) | Development, testing |
marko/queue-database | Database table | Small apps, getting started |
marko/queue-rabbitmq | RabbitMQ | Production, high throughput |
Next Steps
Section titled “Next Steps”- Mail — queue email sending
- Error Handling — handle failed jobs
- Queue package reference — full API details