PHP test Kafka project example


This article describes the PHP test Kafka project as an example. Share with you for your reference, as follows:


Kafka was originally developed by LinkedIn. It is a distributed, partitioned, multi replica, multi subscriber distributed logging system based on zookeeper coordination (which can also be used as an MQ system). It can be commonly used for Web / nginx logs, access logs, message services, etc. LinkedIn contributed to the Apache foundation in 2010 and became a top open source project.

The main application scenarios are: log collection system and message system.

Installing Kafka PHP project dependencies

composer require nmred/kafka-php


require './vendor/autoload.php';
$config = \Kafka\ProducerConfig::getInstance();
$producer = new \Kafka\Producer(function() {
 $t = time();
 return array(
  'topic' => 'test',
  'value' => $t,
  'key' => $t,
$producer->success(function($result) {
$producer->error(function($errorCode) {
 var_dump('error', $errorCode);


require './vendor/autoload.php';
$config = \Kafka\ConsumerConfig::getInstance();
$consumer = new \Kafka\Consumer();
$consumer->start(function($topic, $part, $message) {

Test producer

php produce.php

Test consumer

php consumer.php

For more information about PHP, readers who are interested can see the topics on this site: introduction to PHP object-oriented programming, complete operation skills of PHP array, introduction to PHP basic syntax, summary of PHP operation and operator usage, summary of PHP character string usage Introduction to PHP + MySQL database operation and summary of common PHP database operation skills

I hope this article will help you in PHP programming.

Recommended Today

Implementation example of go operation etcd

etcdIt is an open-source, distributed key value pair data storage system, which provides shared configuration, service registration and discovery. This paper mainly introduces the installation and use of etcd. Etcdetcd introduction etcdIt is an open source and highly available distributed key value storage system developed with go language, which can be used to configure sharing […]