PHPackages                             takatost/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. takatost/php-pubsub-kafka

ActiveLibrary

takatost/php-pubsub-kafka
=========================

A Kafka adapter for the php-pubsub package

1.0.4(9y ago)051MITPHPPHP &gt;=5.6.0

Since Sep 3Pushed 9y ago1 watchersCompare

[ Source](https://github.com/takatost/php-pubsub-kafka)[ Packagist](https://packagist.org/packages/takatost/php-pubsub-kafka)[ RSS](/packages/takatost-php-pubsub-kafka/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (5)Used By (0)

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)[![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

    **PHP5**

    ```
    $ pecl install channel://pecl.php.net/rdkafka-1.0.0
    ```

    **PHP7**

    ```
    $ pecl install channel://pecl.php.net/rdkafka-beta
    ```
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', 'smallest');

$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->setDefaultTopicConf($topicConf);

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

// create producer
$producer = new \RdKafka\Producer();
$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', json_encode(['hello' => 'world']));
$adapter->publish('my_channel', 1);
$adapter->publish('my_channel', false);
```

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 `docker-compose run php-pubsub-kafka /bin/bash`

To run the examples:

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

###  Health Score

26

—

LowBetter than 46% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 85.7% 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 ~23 days

Total

4

Last Release

3415d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bbbdaf4d970a76a33bd811da420e5315d6be9a302f5516cb8357b05c7ef2e4de?d=identicon)[takatost](/maintainers/takatost)

---

Top Contributors

[![matthewgoslett](https://avatars.githubusercontent.com/u/1571743?v=4)](https://github.com/matthewgoslett "matthewgoslett (12 commits)")[![takatost](https://avatars.githubusercontent.com/u/5485478?v=4)](https://github.com/takatost "takatost (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

PHPackages © 2026

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