Download the PHP package myvon/reactphp-rdkafka without Composer

On this page you can find all versions of the php package myvon/reactphp-rdkafka. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package reactphp-rdkafka

reactphp-rdkafka

RdKafka implementation with ReactPHP EventLoop.

This library implement PHP RDKafka from Arnaud-lb with react/event-loop and react/stream and provide a non-blocking event-driven Consumer and Producer.

Latest Version on Packagist Tests Total Downloads

How it works

This package use periodic timers from react/event-loop to consume messages at regular interval. To avoid blocking, timeout is set to 0 when consuming.

It also use react/stream to receive and send message in an event-driven way. Consuming message is done by listening to the data event of the steam. Producing message is done by writing data to the corresponding stream. See Consuming Messages and Producing Messages below.

Installation

You can install the package via composer:

Be sure to have the PHP RDKafka extension installed on your server.

Consuming Messages

To consume message start by creating a Configuration object by passing it the name of your application (used for group.id configuration of kafka, see Consumer group id (general) for more information) and the list of your brokers :

Then, you can create an "Myvon\Kafka\Consumer" instance:

Using Configuration::consumer() generate an RdKafka\Conf instance with correct configuration for a Consumer.

You can then start consuming message by calling the start method of the consumer and passing it the list of topics you want to subscribe :

This method will return an ThroughStream instance, allowing you to listen to the data event to receive messages :

The $data parameter will contain the following keys :

Handling consumer errors

The consumer will write to the stream every message received with error RD_KAFKA_RESP_ERR_NO_ERROR.

RD_KAFKA_RESP_ERR__TIMED_OUT and RD_KAFKA_RESP_ERR__PARTITION_EOF will be ignored.

Every other error will be sent through the error event :

This package does not handle errors, it simply pass it to your application. It's up to you to handle it.

Consumer timeout and periodic timer

By default the timeout passed to the consume method of RdKafka\KafkaConsumer it set to 0. This prevents the method to block the execution of the script. If you want to set a timeout anyway, you can do it by passing the desired timeout (in ms) to the setConsumeTimeout method :

Be aware that this will affect the EventLoop !

BY default the consumer will look for messages every 1 second. You can set this timer by passing the new timer to the setTimerPeriod method :

Notice: It internally use the addPeriodicTimer method of the EventLoop so the timer is in second.

Accessing the KafkaConsumer instance

If you need to access the KafkaConsumer instance directly, you can do it by calling getConsumer:

Producing Messages

Like the Consumer, you need to create the configuration object and pass it to Myvon\Kafka\Producer when instantiating it :

You can pass multiple topic to the start method. Call start will return one instance of ThroughStream by topic you want to publish in. You can access the stream of a given topic by :

You can then write message to the stream, which will by produced to the corresponding topic :

Notice: the producer will ensure every message is sent by calling poll() every 500ms. This delay can be changed by calling setPollInterval. When streams are closed, the producer poll every message and flush them to be sure noting is lost.

I don't want to use the EventLoop when producing message

Sometime, you want to produce message directly without using an eventloop. This can be done by passing false as second argument to the start method :

This will deactivate every usage of the loop in the producer and your code will immediately exit after the last line. To avoid loosing message, streams are closed on the destruction of the class, thanks to the __destruct() method.

Gracefully stopping Consumer and Producer

If you want to stop the Consumer or the Producer before your code end, you can call the stop() method of each class. This will remove every periodic timer and close all streams.

By doing this you will receive the end and close events of every stream used by the Consumer or the Producer.

Using custom configuration option

You can pass custom configuration option to the RdKafka\Conf instance generated by passing them as an array to the thrid arguments of the Myvon\Kafka\Configuration constructor :

Using a custom loop

If you don't want the Consumer or the Producer to use the default loop, you can pass it as second arguments of the constructor of each class :

Notice: passing a loop to the producer will force loop utilization even if you pass false as second argument of start

Testing

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.


All versions of reactphp-rdkafka with dependencies

PHP Build Version
Package Version
Requires ext-rdkafka Version *
react/stream Version ^1.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package myvon/reactphp-rdkafka contains the following files

Loading the files please wait ....