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.1k↓50%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 1mo ago

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 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity26

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

2899d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b13cda5a6abe4145f839778ed29e07e019a06a3120156aa70e5d9733d8116cb3?d=identicon)[Alpari](/maintainers/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

[friendsofsymfony/rest-bundle

This Bundle provides various tools to rapidly develop RESTful API's with Symfony

2.8k73.3M319](/packages/friendsofsymfony-rest-bundle)[php-http/discovery

Finds and installs PSR-7, PSR-17, PSR-18 and HTTPlug implementations

1.3k309.5M1.2k](/packages/php-http-discovery)[pusher/pusher-php-server

Library for interacting with the Pusher REST API

1.5k94.8M293](/packages/pusher-pusher-php-server)[react/http

Event-driven, streaming HTTP client and server implementation for ReactPHP

78026.4M414](/packages/react-http)[php-http/curl-client

PSR-18 and HTTPlug Async client with cURL

48347.0M384](/packages/php-http-curl-client)[smi2/phpclickhouse

PHP ClickHouse Client

84310.1M71](/packages/smi2-phpclickhouse)

PHPackages © 2026

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