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

ActiveLibrary

salebab/kafka-php
=================

Kafka PHP library

067PHP

Since Dec 23Pushed 12y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#kafka-php)

kafka-php allows you to produce messages to the [Apache Kafka](http://incubator.apache.org/kafka/) distributed publish/subscribe messaging service.

Requirements
------------

[](#requirements)

- Minimum PHP version: 5.3.3.
- Apache Kafka 0.6.x or 0.7.x.
- You need to have access to your Kafka instance and be able to connect through TCP. You can obtain a copy and instructions on how to setup kafka at
- The [PHP Zookeeper extension](https://github.com/andreiz/php-zookeeper) is required if you want to use the Zookeeper-based consumer.

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

[](#installation)

Add the lib directory to the PHP include\_path and use an autoloader like the one in the examples directory (the code follows the PEAR/Zend one-class-per-file convention).

Usage
-----

[](#usage)

The examples directory contains an example of a Producer and a simple Consumer, and an example of the Zookeeper-based Consumer.

Example Producer:

```
$producer = new Kafka_Producer('localhost', 9092, Kafka_Encoder::COMPRESSION_NONE);
$messages = array('some', 'messages', 'here');
$topic = 'test';
$bytes = $producer->send($messages, $topic);

```

Example Consumer:

```
$topic         = 'test';
$partition     = 0;
$offset        = 0;
$maxSize       = 1000000;
$socketTimeout = 5;

while (true) {
    $consumer = new Kafka_SimpleConsumer('localhost', 9092, $socketTimeout, $maxSize);
    $fetchRequest = new Kafka_FetchRequest($topic, $partition, $offset, $maxSize);
    $messages = $consumer->fetch($fetchRequest);
    foreach ($messages as $msg) {
        echo "\nMessage: " . $msg->payload();
    }
    //advance the offset after consuming each MessageSet
    $offset += $messages->validBytes();
    unset($fetchRequest);
}

```

TODO
----

[](#todo)

- support for Snappy compression

Contact for questions
---------------------

[](#contact-for-questions)

Lorenzo Alberton

l.alberton at(@) quipo.it

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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/f82b24bc54766089ac9bae50600d087259714e072c917475415cfff90d36f2a8?d=identicon)[salebab](/maintainers/salebab)

---

Top Contributors

[![quipo](https://avatars.githubusercontent.com/u/321794?v=4)](https://github.com/quipo "quipo (12 commits)")[![salebab](https://avatars.githubusercontent.com/u/246858?v=4)](https://github.com/salebab "salebab (4 commits)")

### Embed Badge

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

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

PHPackages © 2026

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