PHPackages                             tina4stack/tina4php-queue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tina4stack/tina4php-queue

ActiveLibrary

tina4stack/tina4php-queue
=========================

Queueing for Tina4Php

v2.0.1(2mo ago)12MITPHPPHP &gt;=8.1CI passing

Since Mar 14Pushed 2mo agoCompare

[ Source](https://github.com/tina4stack/tina4php-queue)[ Packagist](https://packagist.org/packages/tina4stack/tina4php-queue)[ RSS](/packages/tina4stack-tina4php-queue/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Tina4 Queue
===========

[](#tina4-queue)

A lightweight, backend-agnostic queueing system for the Tina4 PHP framework. Supports multiple backends through a unified interface, with generator-based consumption inspired by Python's `yield` pattern.

[![Tests](https://github.com/tina4stack/tina4php-queue/actions/workflows/tests.yml/badge.svg)](https://github.com/tina4stack/tina4php-queue/actions/workflows/tests.yml)

Features
--------

[](#features)

- Generator-based consumption — iterate messages with `foreach`, no polling callbacks
- Multiple backends: LiteQueue (SQLite), RabbitMQ, MongoDB, Kafka
- Multi-queue consumers with round-robin support
- Batch processing for high-throughput scenarios
- Exponential backoff on empty queues (LiteQueue, MongoDB)
- Event-driven consumption for RabbitMQ (`basic_consume`)
- UUIDv7 message IDs — sortable, unique, time-ordered
- Extensible via `QueueInterface` for adding custom backends

Installing
----------

[](#installing)

```
composer require tina4stack/tina4php-queue
```

### Requirements

[](#requirements)

- PHP &gt;= 8.1
- Extensions: `sqlite3`, `bcmath`

### Optional Backend Dependencies

[](#optional-backend-dependencies)

BackendComposer PackageLiteQueue (SQLite)Built-in, no extra dependenciesRabbitMQ`composer require php-amqplib/php-amqplib`MongoDB`composer require mongodb/mongodb`KafkaRequires `ext-rdkafka` PHP extensionQuick Start
-----------

[](#quick-start)

### Producing Messages

[](#producing-messages)

```
$config = new \Tina4\QueueConfig();
$config->queueType = 'litequeue';
$config->litequeueDatabaseName = 'queue.db';

$queue = new \Tina4\Queue($config, 'my-topic');
$producer = new \Tina4\Producer($queue);

$msg = $producer->produce('Hello World', 'user123');
echo "Produced: {$msg->messageId}\n";
```

### Consuming Messages

[](#consuming-messages)

Messages are consumed using PHP generators — no callbacks required.

```
foreach ($queue->consume(acknowledge: true) as $msg) {
    echo "Received: {$msg->data} from user {$msg->userId}\n";
}
```

### Single Message Pull

[](#single-message-pull)

```
$gen = $queue->consume();
$msg = $gen->current(); // Get one message, or wait for one
```

Consumer Patterns
-----------------

[](#consumer-patterns)

### Multi-Queue Consumer

[](#multi-queue-consumer)

Listen to multiple queues simultaneously with round-robin iteration.

```
$queue1 = new \Tina4\Queue($config, 'orders');
$queue2 = new \Tina4\Queue($config, 'notifications');

$consumer = new \Tina4\Consumer([$queue1, $queue2], acknowledge: true, pollInterval: 0.5);

foreach ($consumer->messages() as $msg) {
    echo "From {$msg->topic}: {$msg->data}\n";
}
```

### Blocking Handler

[](#blocking-handler)

For simple workers that process messages with a callback.

```
$consumer = new \Tina4\Consumer($queue);

$consumer->runForever(function (\Tina4\QueueMessage $msg) {
    // Process each message
    echo "Handling: {$msg->data}\n";
});
```

### Batch Processing

[](#batch-processing)

Process multiple messages per poll cycle for higher throughput.

```
$queue = new \Tina4\Queue($config, 'bulk-jobs', batchSize: 10);

foreach ($queue->consume() as $msg) {
    // Up to 10 messages fetched per poll
    processJob($msg);
}
```

Configuration
-------------

[](#configuration)

### QueueConfig Properties

[](#queueconfig-properties)

PropertyTypeDefaultDescription`queueType`string`'litequeue'`Backend type: `litequeue`, `rabbitmq`, `mongo-queue`, `kafka``litequeueDatabaseName`string`'queue.db'`SQLite database file path`rabbitmqConfig`array|null`null`RabbitMQ connection: `host`, `port`, `user`, `password``mongoQueueConfig`array|null`null`MongoDB connection: `host`, `port`, `username`, `password``kafkaConfig`array|null`null`Kafka config: `bootstrap.servers`, etc.`prefix`string`''`Namespace prefix for queue/topic names`pollInterval`float`0.1`Seconds between polls when queue is empty`maxBackoff`float`5.0`Maximum backoff ceiling (seconds) for exponential backoff### Backend Configuration Examples

[](#backend-configuration-examples)

**RabbitMQ**

```
$config = new \Tina4\QueueConfig();
$config->queueType = 'rabbitmq';
$config->rabbitmqConfig = [
    'host' => 'localhost',
    'port' => 5672,
    'user' => 'guest',
    'password' => 'guest'
];
```

**MongoDB**

```
$config = new \Tina4\QueueConfig();
$config->queueType = 'mongo-queue';
$config->mongoQueueConfig = [
    'host' => 'localhost',
    'port' => 27017,
    'username' => 'admin',
    'password' => 'secret'
];
```

**Kafka**

```
$config = new \Tina4\QueueConfig();
$config->queueType = 'kafka';
$config->kafkaConfig = [
    'bootstrap.servers' => 'localhost:9092'
];
```

### Prefix Namespacing

[](#prefix-namespacing)

Use the `prefix` property to isolate queue topics by environment.

```
$config->prefix = 'dev';
// LiteQueue table: dev_my_topic
// RabbitMQ exchange: dev_my-topic
// MongoDB collection: dev_my-topic
```

QueueMessage Properties
-----------------------

[](#queuemessage-properties)

Each consumed or produced message is a `QueueMessage` with readonly properties.

PropertyTypeDescription`messageId`stringUUIDv7 — unique, time-sortable`data`stringThe message payload`userId`string|nullAssociated user identifier`status`int`0` pending, `1` processing, `2` acknowledged`timestamp`intNanosecond timestamp (`hrtime`)`deliveryTag`stringBackend-specific delivery tag`topic`stringQueue topic name (for multi-queue consumers)Producer
--------

[](#producer)

The `Producer` wrapper provides a cleaner API that throws on failure instead of returning exceptions.

```
$producer = new \Tina4\Producer($queue, deliveryCallback: function ($backend, $err, $msg) {
    if ($err) {
        error_log("Delivery failed: " . $err->getMessage());
    }
});

try {
    $msg = $producer->produce('payload', 'user-42');
} catch (\Tina4\QueueException $e) {
    // Handle failure
}
```

Backend Comparison
------------------

[](#backend-comparison)

FeatureLiteQueueRabbitMQMongoDBKafkaExternal serviceNoneRabbitMQ brokerMongoDB serverKafka clusterConsume strategyExponential backoff pollEvent-driven (`basic_consume`)Exponential backoff pollTimeout-based (`consume`)PersistenceSQLite fileBroker (durable)Document storeCommit logDistributedNoYesYesYesMessage orderingFIFOFIFOFIFO (sorted by `in_time`)Partitioned FIFOBest forDevelopment, low volumeReliable messagingDocument-oriented appsHigh-throughput streamingRun Tests
---------

[](#run-tests)

```
composer test
```

All tests use LiteQueue with temporary SQLite databases — no external services required.

License
-------

[](#license)

MIT — see [LICENSE](LICENSE) for details.

---

Our Sponsors
------------

[](#our-sponsors)

**Sponsored with 🩵 by Code Infinity**

[![Code Infinity](https://camo.githubusercontent.com/1516fb1662e3486bce77822177a5ea199edc32ea109369812592ec9bca38159a/68747470733a2f2f636f6465696e66696e6974792e636f2e7a612f77702d636f6e74656e742f75706c6f6164732f323032352f30392f6338652d6c6f676f2d6769746875622e706e67)](https://codeinfinity.co.za/about-open-source-policy?utm_source=github&utm_medium=website&utm_campaign=opensource_campaign&utm_id=opensource)

*Supporting open source communities • Innovate • Code • Empower*

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance87

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

64d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/82961293?v=4)[Tina4](/maintainers/tina4stack)[@tina4stack](https://github.com/tina4stack)

---

Top Contributors

[![andrevanzuydam](https://avatars.githubusercontent.com/u/6102941?v=4)](https://github.com/andrevanzuydam "andrevanzuydam (7 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tina4stack-tina4php-queue/health.svg)

```
[![Health](https://phpackages.com/badges/tina4stack-tina4php-queue/health.svg)](https://phpackages.com/packages/tina4stack-tina4php-queue)
```

###  Alternatives

[tina4stack/tina4php

Tina4 PHP — This is not a 4ramework

208.8k9](/packages/tina4stack-tina4php)[andrevanzuydam/tina4php

Tina4 for PHP — 54 built-in features, zero dependencies

272.4k](/packages/andrevanzuydam-tina4php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
