1. Go to this page and download the library: Download linwanfeng/kafka-php-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
linwanfeng / kafka-php-sdk example snippets
use kafkaPhp\KafkaProducer;
use kafkaPhp\KafkaException;
try{
$kafkaClient = new KafkaProducer('127.0.0.1:9092');
$kafkaClient->sendMsg('topic', 'msg');
}catch (KafkaException $e){
echo $e->getErrorMessage();die;
}
use kafkaPhp\KafkaSkProducer;
use kafkaPhp\KafkaException;
try{
$kafkaClient = new KafkaSkProducer('***.***.*.***', '***');
$response = $kafkaClient->sendMsg('topic', 'msg');
}catch (KafkaException $e){
echo $e->getErrorMessage();
}