PHPackages                             superbalist/php-pubsub-kafka - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. superbalist/php-pubsub-kafka

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

superbalist/php-pubsub-kafka
============================

A Kafka adapter for the php-pubsub package

2.0.0(8y ago)3166.7k16[2 PRs](https://github.com/Superbalist/php-pubsub-kafka/pulls)2MITPHPPHP &gt;=5.6.0

Since Sep 3Pushed 3y ago36 watchersCompare

[ Source](https://github.com/Superbalist/php-pubsub-kafka)[ Packagist](https://packagist.org/packages/superbalist/php-pubsub-kafka)[ RSS](/packages/superbalist-php-pubsub-kafka/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (6)Used By (2)

php-pubsub-kafka
================

[](#php-pubsub-kafka)

A Kafka adapter for the [php-pubsub](https://github.com/Superbalist/php-pubsub) package.

[![Author](https://camo.githubusercontent.com/abd4e3e2e71081ad01ef09a60c49d70c5e0677497f38918e740703cd02605078/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d40737570657262616c6973742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/superbalist)[![Build Status](https://camo.githubusercontent.com/7a976c3840d0ba6b62fca55433be4703a9c7383273121b8849adc8c51907dfb8/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f537570657262616c6973742f7068702d7075627375622d6b61666b612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Superbalist/php-pubsub-kafka)[![StyleCI](https://camo.githubusercontent.com/ca4c2ce7aaef1734219942e15ec496027d9b36874d6a851cc5538dcca01dde86/68747470733a2f2f7374796c6563692e696f2f7265706f732f36373235353334372f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/67255347)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Packagist Version](https://camo.githubusercontent.com/0e6e40dac528425acce8183ab7f71561f2c4941d90729fa8cf2f48fb1f1fc293/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f737570657262616c6973742f7068702d7075627375622d6b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/superbalist/php-pubsub-kafka)[![Total Downloads](https://camo.githubusercontent.com/33f3c9fe373d6c3805301ab9fefc2bcf0edaed8361f785bbd16135fac6c24842/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737570657262616c6973742f7068702d7075627375622d6b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/superbalist/php-pubsub-kafka)

Installation
------------

[](#installation)

1. Install [librdkafka c library](https://github.com/edenhill/librdkafka)

    ```
    $ cd /tmp
    $ mkdir librdkafka
    $ cd librdkafka
    $ git clone https://github.com/edenhill/librdkafka.git .
    $ ./configure
    $ make
    $ make install
    ```
2. Install the [php-rdkafka](https://github.com/arnaud-lb/php-rdkafka) PECL extension

    ```
    $ pecl install rdkafka
    ```
3. Add the following to your php.ini file to enable the php-rdkafka extension `extension=rdkafka.so`
4. `composer require superbalist/php-pubsub-kafka`

Usage
-----

[](#usage)

```
// create consumer
$topicConf = new \RdKafka\TopicConf();
$topicConf->set('auto.offset.reset', 'largest');

$conf = new \RdKafka\Conf();
$conf->set('group.id', 'php-pubsub');
$conf->set('metadata.broker.list', '127.0.0.1');
$conf->set('enable.auto.commit', 'false');
$conf->set('offset.store.method', 'broker');
$conf->set('socket.blocking.max.ms', 50);
$conf->setDefaultTopicConf($topicConf);

$consumer = new \RdKafka\KafkaConsumer($conf);

// create producer
$conf = new \RdKafka\Conf();
$conf->set('socket.blocking.max.ms', 50);
$conf->set('queue.buffering.max.ms', 20);

$producer = new \RdKafka\Producer($conf);
$producer->addBrokers('127.0.0.1');

$adapter = new \Superbalist\PubSub\Kafka\KafkaPubSubAdapter($producer, $consumer);

// consume messages
// note: this is a blocking call
$adapter->subscribe('my_channel', function ($message) {
    var_dump($message);
});

// publish messages
$adapter->publish('my_channel', 'HELLO WORLD');
$adapter->publish('my_channel', ['hello' => 'world']);
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);

// publish multiple messages
$messages = [
    ['hello' => 'world'],
    'lorem ipsum',
];
$adapter->publishBatch('my_channel', $messages);
```

Examples
--------

[](#examples)

The library comes with [examples](examples) for the adapter and a [Dockerfile](Dockerfile) for running the example scripts.

Run `make up`.

You will start at a `bash` prompt in the `/opt/php-pubsub` directory.

If you need another shell to publish a message to a blocking consumer, you can run `make shell`

To run the examples:

```
$ php examples/KafkaConsumerExample.php
$ php examples/KafkaPublishExample.php (in a separate shell)
```

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity40

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 88.5% 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 ~85 days

Total

4

Last Release

3279d ago

Major Versions

1.0.2 → 2.0.02017-05-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b8f533cf5a84c29d3860ee32356f0554ead023247638ea952353fc2f01b2e5d?d=identicon)[superbalist](/maintainers/superbalist)

---

Top Contributors

[![matthewgoslett](https://avatars.githubusercontent.com/u/1571743?v=4)](https://github.com/matthewgoslett "matthewgoslett (23 commits)")[![shad0wfir3](https://avatars.githubusercontent.com/u/20926935?v=4)](https://github.com/shad0wfir3 "shad0wfir3 (3 commits)")

---

Tags

kafkaphpphp-pubsubphp-pubsub-kafkaphp-rdkafkapubsubsuperbalist

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/superbalist-php-pubsub-kafka/health.svg)

```
[![Health](https://phpackages.com/badges/superbalist-php-pubsub-kafka/health.svg)](https://phpackages.com/packages/superbalist-php-pubsub-kafka)
```

PHPackages © 2026

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