Osx-how can I use the php client to connect to kafka? How can I refresh client data by monitoring broker changes?

Source: Internet
Author: User
I have recently studied using php to connect kafka. the nmredkafka-php project code on githup is currently: 1. kafka, 2. test: Run phpProduce on the command line. php and consumer can also obtain data. Problem: 1. how does the consumer end keep executing? Write... I have recently studied using php to connect kafka.
Use the nmred/kafka-php project code on githup.
Currently:
1. You can connect to kafka on the server,
2. Test: run php Produce. php on the command line to obtain data from the consumer.
Problem:
1. How does the consumer end keep executing? Is it a while dead loop?
2. How does kafka-php pull new information from the client and refresh the client data in an interval?
3. What does this sentence mean in README. md:

 Watches broker state, if broker changes, the client will refresh     broker and topic metadata stored in the client?

I am not very grateful for your use of this tool!

Supplement: Now my php client consumer can receive data, but it always contains garbled characters. For example, if I input nihao in the producer segment, php consumer. php will output:
# Nihao

The question is:
1. Why is nihao input from the producer end, but the output information from the consumer end is not nihao?
2. Why is there a garbled string?
3. How can this problem be solved?
4. The core code read by socket is attached below:

// Obtain the consumer information, where $ this-> stream is a socket object with a successful socket connection:
$ Msg = $ this-> stream-> read ($ messageSize, true );

The core code of the read method is as follows:
$ Readable = @ stream_select ($ read, $ null, $ null, $ this-> recvTimeoutSec, $ this-> recvTimeoutUsec );

    if ($readable > 0) {        $remainingBytes = $len;        $data = $chunk = '';        while ($remainingBytes > 0) {            $chunk = fread($this->stream, $remainingBytes);            if ($chunk === false) {                $this->close();                throw new \Kafka\Exception\SocketEOF('Could not read '.$len.' bytes from stream (no data)');            }            if (strlen($chunk) === 0) {                // Zero bytes because of EOF?                if (feof($this->stream)) {                    $this->close();                    throw new \Kafka\Exception\SocketEOF('Unexpected EOF while reading '.$len.' bytes from stream (no data)');                }                // Otherwise wait for bytes                $readable = @stream_select($read, $null, $null, $this->recvTimeoutSec, $this->recvTimeoutUsec);                if ($readable !== 1) {                    throw new \Kafka\Exception\SocketTimeout('Timed out reading socket while reading ' . $len . ' bytes with ' . $remainingBytes . ' bytes to go');                }                continue; // attempt another read            }            $data .= $chunk;            $remainingBytes -= strlen($chunk);        }

Concatenate information through this while loop. The point is that the $ chunk from fread contains garbled characters.

Call experts!

Reply content:

I have recently studied using php to connect kafka.
Use the nmred/kafka-php project code on githup.
Currently:
1. You can connect to kafka on the server,
2. Test: run php Produce. php on the command line to obtain data from the consumer.
Problem:
1. How does the consumer end keep executing? Is it a while dead loop?
2. How does kafka-php pull new information from the client and refresh the client data in an interval?
3. What does this sentence mean in README. md:

 Watches broker state, if broker changes, the client will refresh     broker and topic metadata stored in the client?

I am not very grateful for your use of this tool!

Supplement: Now my php client consumer can receive data, but it always contains garbled characters. For example, if I input nihao in the producer segment, php consumer. php will output:
# Nihao

The question is:
1. Why is nihao input from the producer end, but the output information from the consumer end is not nihao?
2. Why is there a garbled string?
3. How can this problem be solved?
4. The core code read by socket is attached below:

// Obtain the consumer information, where $ this-> stream is a socket object with a successful socket connection:
$ Msg = $ this-> stream-> read ($ messageSize, true );

The core code of the read method is as follows:
$ Readable = @ stream_select ($ read, $ null, $ null, $ this-> recvTimeoutSec, $ this-> recvTimeoutUsec );

    if ($readable > 0) {        $remainingBytes = $len;        $data = $chunk = '';        while ($remainingBytes > 0) {            $chunk = fread($this->stream, $remainingBytes);            if ($chunk === false) {                $this->close();                throw new \Kafka\Exception\SocketEOF('Could not read '.$len.' bytes from stream (no data)');            }            if (strlen($chunk) === 0) {                // Zero bytes because of EOF?                if (feof($this->stream)) {                    $this->close();                    throw new \Kafka\Exception\SocketEOF('Unexpected EOF while reading '.$len.' bytes from stream (no data)');                }                // Otherwise wait for bytes                $readable = @stream_select($read, $null, $null, $this->recvTimeoutSec, $this->recvTimeoutUsec);                if ($readable !== 1) {                    throw new \Kafka\Exception\SocketTimeout('Timed out reading socket while reading ' . $len . ' bytes with ' . $remainingBytes . ' bytes to go');                }                continue; // attempt another read            }            $data .= $chunk;            $remainingBytes -= strlen($chunk);        }

Concatenate information through this while loop. The point is that the $ chunk from fread contains garbled characters.

Call experts!

Consumer should be able to judge whether the broker has changed through loops, and then update the description.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.