GithubHelp home page GithubHelp logo

ifa6 / phpkafka Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evodelavega/phpkafka

0.0 3.0 0.0 277 KB

PHP extension for Apache Kafka

License: MIT License

C 86.15% Shell 0.37% PHP 13.48%

phpkafka's Introduction

#This fork is still being actively developed

Given that the original repo is no longer supported by the author, I've decided to keep working at this PHP-Kafka extension instead. The branch where most of the work is being done is the consume-with-meta branch.

Changes that have happened thusfar:

  • Timeout when disconnecting is reduced (significantly)
  • Connections can be closed as you go
  • The librdkafka meta API is used
  • New methods added (Kafka::getTopics, Kafka::getPartitionsFor($topic) most notable additions)
  • Kafka::set_partition is deprecated, in favour of the more PSR-compliant Kafka::setPartition method
  • A PHP stub was added for IDE code-completion
  • Argument checks were added, and exceptions are thrown in some places
  • Class constants for an easier API (Kafka::OFFSET_*)
  • The extension logged everything in /var/etc/syslog, this is still the default behaviour (as this extension is under development), but can be turned off (Kafka::setLogLevel(Kafka::LOG_OFF))
  • Exceptions (KafkaException) in case of errors (still work in progress, though)
  • Thread-safe Kafka connections

Changes that are on the TODO list include:

  • Separating kafka meta information out into a separate class (KafkaTopic and KafkaMessage classes)
  • Support for multiple kafka connections
  • Allow PHP to determine what the timeouts should be (mainly when disconnecting, or producing messages)
  • Add custom exceptions
  • Overall API improvements
  • Performance!
  • CI (travis)
  • Adding tests to the build
  • PHP7 support

All help is welcome, of course...

PHP extension for Apache Kafka 0.8. It's built on top of kafka C driver (librdkafka). This extension requires the version 0.8.6 (ubuntu's librdkafka packages won't do it, they do not implement the meta API yet).

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
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->produce("topic_name", "message content");
//get all the available partitions
$partitions = $kafka->getPartitionsForTopic('topic_name');
//use it to OPTIONALLY specify a partition to consume from
//if not, consuming IS slower. To set the partition:
$kafka->setPartition($partitions[0]);//set to first partition
//then consume, for example, starting with the first offset, consume 20 messages
$msg = $kafka->consume("topic_name", Kafka::OFFSET_BEGIN, 20);
var_dump($msg);//dumps array of messages

phpkafka's People

Contributors

yllierop avatar salebab avatar evodelavega avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.