Skip to content

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.

Terminal window
# Database-backed queue
composer require marko/queue marko/queue-database
# RabbitMQ queue
composer require marko/queue marko/queue-rabbitmq
app/blog/Job/SendWelcomeEmail.php
<?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
}
}
app/blog/Service/RegistrationService.php
<?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,
));
}
}
Terminal window
marko queue:work
PackageBackendBest For
marko/queue-syncSynchronous (inline)Development, testing
marko/queue-databaseDatabase tableSmall apps, getting started
marko/queue-rabbitmqRabbitMQProduction, high throughput