ofeng / phpkafka

php kafka extension

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

phpkafka

PHP extension for Apache Kafka 0.8. It's built on top of kafka C driver (librdkafka). It makes persistent connection to kafka broker with non-blocking calls, so it should be very fast.

IMPORTANT: Library is in heavy development and some features are not implemented yet.

Requirements:

Download and install librdkafka. Run sudo ldconfig to update shared libraries.

Installing PHP extension:

phpize
./configure --enable-kafka --with-php-config=/path/to/php-config
make
sudo make install
sudo sh -c 'echo "extension=kafka.so" >> /etc/php5/conf.d/kafka.ini'
#For CLI mode:
sudo sh -c 'echo "extension=kafka.so" >> /etc/php5/cli/conf.d/20-kafka.ini'

Examples:

// Produce a message
$kafka = new Kafka("localhost:9092");
$kafka->set_topic("topic_name");
$kafka->produce("message content");
// Consume a message
$kafka = new Kafka("localhost:9092");
$kafka->set_topic("topic_name");
$msg = $kafka->consume(10,10);
print_r($msg);

About

php kafka extension

License:MIT License


Languages

Language:C 98.5%Language:Shell 1.5%