Download the PHP package jenner/kafka-php without Composer
On this page you can find all versions of the php package jenner/kafka-php. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jenner/kafka-php
More information about jenner/kafka-php
Files in jenner/kafka-php
Package kafka-php
Short Description Kafka client for php
License BSD-3-Clause
Homepage http://wwww.swanlinux.net
Informations about the package kafka-php
Kafka-php
Kafka-php is a php client with Zookeeper integration for apache Kafka. It only supports the latest version of Kafka 0.8 which is still under development, so this module is not production ready so far.
The Zookeeper integration does the following jobs:
- Loads broker metadata from Zookeeper before we can communicate with the Kafka server
- Watches broker state, if broker changes, the client will refresh broker and topic metadata stored in the client
Requirements
- Minimum PHP version: 5.3.3.
- Apache Kafka 0.8.x
- You need to have access to your Kafka instance and be able to connect through TCP. You can obtain a copy and instructions on how to setup kafka at https://github.com/kafka-dev/kafka kafka-08-quick-start
- The PHP Zookeeper extension
Installation
Add the lib directory to the PHP include_path and use an autoloader like the one in the examples directory (the code follows the PEAR/Zend one-class-per-file convention).
Produce
\Kafka\Produce::getInstance($hostList, $timeout)
hostList
: zookeeper host list , example 127.0.0.1:2181,192.168.1.114:2181timeout
: zookeeper timeout
\Kafka\Produce::setRequireAck($ack = -1)
ack
: This field indicates how many acknowledgements the servers should receive before responding to the request.
\Kafka\Produce::setMessages($topicName, $partitionId, $messages)
topicName
: The topic that data is being published to.partitionId
: The partition that data is being published to.messages
: [Array] publish message.
\Kafka\Produce::send()
send message sets to the server.
Example
Consumer
\Kafka\Consumer::getInstance($hostList, $timeout)
hostList
: zookeeper host list , example 127.0.0.1:2181,192.168.1.114:2181timeout
: zookeeper timeout
\Kafka\Consumer::setGroup($groupName)
groupName
: Specify consumer group.
\Kafka\Consumer::setPartition($topicName, $partitionId, $offset = 0)
topicName
: The topic that data is being fetch to.partitionId
: The partition that data is being fetch to.offset
: set fetch offset. default0
.
\Kafka\Consumer::fetch()
return fetch message Iterator. \Kafka\Protocol\Fetch\Topic
\Kafka\Protocol\Fetch\Topic
this object is iterator
key
: topic name
value
: \Kafka\Protocol\Fetch\Partition
\Kafka\Protocol\Fetch\Partition
this object is iterator.
key
: partition id
value
: messageSet object
\Kafka\Protocol\Fetch\Partition::getErrCode()
return partition fetch errcode.
\Kafka\Protocol\Fetch\Partition::getHighOffset()
return partition fetch offset.
\Kafka\Protocol\Fetch\MessageSet
this object is iterator. \Kafka\Protocol\Fetch\Message
Example
Basic Protocol
Produce API
The produce API is used to send message sets to the server. For efficiency it allows sending message sets intended for many topic partitions in a single request.
\Kafka\Protocol\Encoder::produceRequest
Param struct
Return
Array
Example
Fetch API
The fetch API is used to fetch a chunk of one or more logs for some topic-partitions. Logically one specifies the topics, partitions, and starting offset at which to begin the fetch and gets back a chunk of messages
\Kafka\Protocol\Encoder::fetchRequest
Param struct
Return
\Kafka\Protocol\Fetch\Topic iterator
Example
Offset API
This API describes the valid offset range available for a set of topic-partitions. As with the produce and fetch APIs requests must be directed to the broker that is currently the leader for the partitions in question. This can be determined using the metadata API.
\Kafka\Protocol\Encoder::offsetRequest
param struct
Return
Array.
Example
Metadata API
The metdata returned is at the partition level, but grouped together by topic for convenience and to avoid redundancy. For each partition the metadata contains the information for the leader as well as for all the replicas and the list of replicas that are currently in-sync.
\Kafka\Protocol\Encoder::metadataRequest
param struct
Return
Array.
Example
Offset Commit API
These APIs allow for centralized management of offsets.
\Kafka\Protocol\Encoder::commitOffsetRequest
param struct
Return
Array.
Example
Offset Fetch API
These APIs allow for centralized management of offsets.
\Kafka\Protocol\Encoder::fetchOffsetRequest
param struct
Return
Array.