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

ActiveLibrary

milind/php-pubsub-kafka
=======================

A Kafka adapter for the php-pubsub package

066PHP

Since Sep 22Pushed 4y agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#php-pubsub-kafka)

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

[![Author](https://camo.githubusercontent.com/89d1829c61afc8a92333fe0e830ad71714d9fa0cb84cea315ba6162304ff688b/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406d696c696e642d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/milind)[![Build Status](https://camo.githubusercontent.com/ee49abf6201aa508aef43eb44383c574a10f472f5d118a9242a59f9d4fbeba98/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d696c696e642f7068702d7075627375622d6b61666b612f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/milind/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/d5c15c72d4cd0503732c99cc881a1b2fd45e101057cf96ba7302319ee01dc118/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d696c696e642f7068702d7075627375622d6b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/milind/php-pubsub-kafka)[![Total Downloads](https://camo.githubusercontent.com/b7f00a71907fc76aaebc9c60b657d6389282a256a3338a0647a910eecf7ce8d6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d696c696e642f7068702d7075627375622d6b61666b612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/milind/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 milind/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 \milind\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

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity28

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd0035e6fda13036e33240c5018bba0914101219b774998cebb073c4a7ef2abe?d=identicon)[little-isaac](/maintainers/little-isaac)

---

Top Contributors

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

### Embed Badge

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

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

PHPackages © 2026

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