arquivei/php-kafka

PHP Kafka Client

Maintainers

👁 arquivei

Package info

github.com/arquivei/php-kafka

pkg:composer/arquivei/php-kafka

Statistics

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 1

v0.1-alpha 2020-11-19 12:40 UTC

Requires

Suggests

Provides

None

Conflicts

None

Replaces

None

MIT 2ceb09aaddc8b2348d4e52ce5be252a6604c7e05

phpclientkafka

This package is auto-updated.

Last update: 2026-06-12 03:27:30 UTC


README

👁 Build Status

A PHP client for Apache Kafka

Requirements

  • PHP 7.4
  • librdkafka 1.1.0
  • rdkafka 3.x

Install

  1. Install librdkafka c library

    $ cd /tmp
    $ mkdir librdkafka
    $ cd librdkafka
    $ curl -L https://github.com/edenhill/librdkafka/archive/v1.0.0.tar.gz | tar xz
    $ cd librdkafka-1.0.0
    $ ./configure
    $ make
    $ make install
  2. Install the 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. Install this package via composer using:

    composer require arquivei/php-kafka-consumer

Usage

<?php

require_once 'vendor/autoload.php';

use Kafka\Consumer\Entities\Config;
use Kafka\Consumer\Contracts\ConsumerDLQ;
use Kafka\Consumer\Entities\Config\Sasl;
use Kafka\Consumer\Entities\Config\MaxAttempt;

class DefaultConsumer extends Consumer
{
 public function handle(string $message): void
 {
 print 'Init: ' . date('Y-m-d H:i:s') . PHP_EOL;
 sleep(2);
 print 'Finish: ' . date('Y-m-d H:i:s') . PHP_EOL;
 }
}

$config = new Config(
 new Sasl('username', 'pasword', 'mechanisms'),
 'topic',
 'broker:port',
 1,
 'php-kafka-consumer-group-id',
 new DefaultConsumer(),
 'security-protocol'
);

(new \PHP\Kafka\Consumer($config))->consume();



$config = new Config(
 new Sasl('username', 'pasword', 'mechanisms'),
 'topic',
 'broker:port',
 1,
 'php-kafka-consumer-group-id',
 new DLDConsumer(),
 new DLQ("parking-lot"),
 'security-protocol'
);

(new \PHP\Kafka\Consumer($config))->consume();