PHPackages                             alpari/kafka-client - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. alpari/kafka-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

alpari/kafka-client
===================

Implementation of Kafka Client in PHP

0.10.2(8y ago)141.2k↓94.1%1MITPHPPHP ~5.6

Since Aug 12Pushed 6y ago3 watchersCompare

[ Source](https://github.com/alpari-tech/kafka-client)[ Packagist](https://packagist.org/packages/alpari/kafka-client)[ RSS](/packages/alpari-kafka-client/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (10)Used By (0)

PHP Native Apache Kafka Client
------------------------------

[](#php-native-apache-kafka-client)

`alpari/kafka-client` is a PHP library implementation of the Apache Kafka protocol, containing both Producer and Consumer support. It was designed to be as close to PHP as possible, keeping API and config as close to the original ones as possible.

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

[](#installation)

`alpari/kafka-client` can be installed with composer. Installation is quite easy, just ask the Composer to download the library with its dependencies by running the command:

```
$ composer require alpari/kafka-client
```

This library contains several branches, each branch contains support for specfic version of Apache Kafka, see mapping below:

- Branch 0.8.x is suited for Kafka 0.8.0 versions
- Branch 0.9.x is suited for Kafka 0.9.0 versions
- Branch 0.10.x is suited for Kafka 0.10.0 versions
- Branch master is suited for Kafka 0.11.0 versions

Producer API
------------

[](#producer-api)

The Producer API allows applications to send streams of data to topics in the Kafka cluster.

Example showing how to use the producer is given below:

```
use Alpari\Kafka\DTO\Message;
use Alpari\Kafka\Producer\Config;
use Alpari\Kafka\Producer\KafkaProducer;

include __DIR__ . '/vendor/autoload.php';

$producer = new KafkaProducer([
    Config::BOOTSTRAP_SERVERS => ['tcp://localhost'],
]);
$result = $producer->send('test', Message::fromValue('foo'));
```

Only required option is `Config::BOOTSTRAP_SERVERS` which should describe list of Kafka servers used to bootstrap connections to Kafka.

For additional options, please see `Alpari\Kafka\Producer\Config` constants description and [producer configuration](https://kafka.apache.org/documentation/#producerconfigs).

Consumer API
------------

[](#consumer-api)

The Consumer API allows applications to read streams of data from topics in the Kafka cluster.

Example showing how to use the consumer is given below.

```
use Alpari\Kafka;
use Alpari\Kafka\Consumer\Config;
use Alpari\Kafka\Consumer\KafkaConsumer;

$consumer = new KafkaConsumer([
    Config::BOOTSTRAP_SERVERS       => ['tcp://localhost'],
    Config::GROUP_ID                => 'Kafka-Daemon',
    Config::FETCH_MAX_WAIT_MS       => 5000,
    Config::AUTO_OFFSET_RESET       => Kafka\Consumer\OffsetResetStrategy::LATEST,
    Config::SESSION_TIMEOUT_MS      => 30000,
    Config::AUTO_COMMIT_INTERVAL_MS => 10000,
    Config::METADATA_CACHE_FILE     => '/tmp/metadata.php',
]);
$consumer->subscribe(['test']);
for ($i=0; $ipoll(1000);
    echo json_encode($data), PHP_EOL;
}
```

For detailed description of configuration, please visit [consumer configuration](https://kafka.apache.org/documentation/#newconsumerconfigs).

PHP-specific configuration
--------------------------

[](#php-specific-configuration)

This library introduces some specific configuration options in order to work faster with PHP:

- `metadata.cache.file` File name that stores the metadata, this file will be effectively cached by the Opcode cache in production
- `stream.async.connect` Should client use asynchronous connection to the broker
- `stream.persistent.connection` Should client use persistent connection to the cluster or not.

For publishing events from web-requests it is recommended to enable persistent connection and configuring path for metadata cache. In this case publishing of event will be as fast as possible.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.9% 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 ~45 days

Recently: every ~67 days

Total

7

Last Release

2945d ago

### Community

Maintainers

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

---

Top Contributors

[![lisachenko](https://avatars.githubusercontent.com/u/640114?v=4)](https://github.com/lisachenko "lisachenko (203 commits)")[![edefimov](https://avatars.githubusercontent.com/u/12027442?v=4)](https://github.com/edefimov "edefimov (10 commits)")[![berezuev](https://avatars.githubusercontent.com/u/695546?v=4)](https://github.com/berezuev "berezuev (1 commits)")

---

Tags

kafka-clientnativephp

### Embed Badge

![Health badge](/badges/alpari-kafka-client/health.svg)

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

###  Alternatives

[php-http/cache-plugin

PSR-6 Cache plugin for HTTPlug

25126.1M82](/packages/php-http-cache-plugin)[illuminate/http

The Illuminate Http package.

11937.9M6.9k](/packages/illuminate-http)[rdkafka/rdkafka

A PHP extension for Kafka

2.2k24.3k1](/packages/rdkafka-rdkafka)[httpsoft/http-message

Strict and fast implementation of PSR-7 and PSR-17

87965.9k114](/packages/httpsoft-http-message)[mezzio/mezzio-router

Router subcomponent for Mezzio

265.4M92](/packages/mezzio-mezzio-router)[serpapi/google-search-results-php

Get Google, Bing, Baidu, Ebay, Yahoo, Yandex, Home depot, Naver, Apple, Duckduckgo, Youtube search results via SerpApi.com

69127.2k](/packages/serpapi-google-search-results-php)

PHPackages © 2026

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