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.