OmniPHP0.x

Documentation / OmniPHP

Queues & background jobs

Separate long-running work from the HTTP request lifecycle.

Configure jobs

Configure Redis Stream queues and register your job handler classes in config/queue.php under handlers, keyed by job name. Handlers receive task data via handle(array $data). Design jobs to be idempotent because retries and reclaimed messages can occur.

Produce jobs

Producer supports regular, high and low priority jobs, delayed jobs and batches. The example assumes the catalog.refresh handler is registered.

php
use OmniPHP\Queue\Producer;

// Register 'catalog.refresh' in config/queue.php handlers.
$producer = new Producer();
$producer->push('catalog.refresh', ['id' => 7]);
$producer->pushDelayed('catalog.refresh', ['id' => 8], 60);

Consume jobs

Create a dedicated Workerman worker in your bootstrapped server, initialize its Consumer after fork and stop it before shutdown. Start all workers with Worker::runAll().

php
use OmniPHP\Queue\Consumer;
use Workerman\Worker;

$worker = new Worker();
$worker->name = 'Queue';
$consumer = null;

$worker->onWorkerStart = function () use (&$consumer) {
    $consumer = new Consumer();
    $consumer->consume();
};
$worker->onWorkerStop = function () use (&$consumer) {
    $consumer?->stop();
};

Delivery and retries

Redis Streams support pending messages, retries and dead-letter queues. Monitor failed jobs and handle replay explicitly.

Next guideRuntime & async I/O