Recently in the study with PHP Lian Kafka.
Using the Nmred/kafka-php Project code on the Githup
Currently
1. You can already connect to the Kafka on the server,
2. Test: Command line execution PHP Produce.php,consumer end can also get data
Problem:
How does the 1.consumer end always execute while the dead loop is written?
2.kafka-php is how to do the client interval time to pull new information and refresh the client data?
3. What is the meaning of this sentence in readme.md:
Watches broker state, if broker changes, the client will refresh broker and topic metadata stored in the client?
Please use the tool to enlighten the idea, not very grateful!
Add: Now my PHP client consumer can receive data, but always contain garbled characters, such as I input in the producer segment: Nihao, then PHP consumer.php, will output:
M 5 3 SNAPPY '; Nihao
Now the question is:
1. Why is the producer end input: Nihao, but the information output on the consumer side is not Nihao?
2. Why is there a string of garbled characters?
3. How to solve?
4. The core code read by the socket is attached below:
Gets the information for the consumer end, where $this->stream is a socket successfully connected socket object:
$msg = $this->stream->read ($messageSize, true);
The Read method core code 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->rec Vtimeoutsec, $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); }
Use this while loop to splice information. The point is that the $chunk that fread out contains garbled characters.
Call Master!
Reply content:
Recently in the study with PHP Lian Kafka.
Using the Nmred/kafka-php Project code on the Githup
Currently
1. You can already connect to the Kafka on the server,
2. Test: Command line execution PHP Produce.php,consumer end can also get data
Problem:
How does the 1.consumer end always execute while the dead loop is written?
2.kafka-php is how to do the client interval time to pull new information and refresh the client data?
3. What is the meaning of this sentence in readme.md:
Watches broker state, if broker changes, the client will refresh broker and topic metadata stored in the client?
Please use the tool to enlighten the idea, not very grateful!
Add: Now my PHP client consumer can receive data, but always contain garbled characters, such as I input in the producer segment: Nihao, then PHP consumer.php, will output:
M 5 3 SNAPPY '; Nihao
Now the question is:
1. Why is the producer end input: Nihao, but the information output on the consumer side is not Nihao?
2. Why is there a string of garbled characters?
3. How to solve?
4. The core code read by the socket is attached below:
Gets the information for the consumer end, where $this->stream is a socket successfully connected socket object:
$msg = $this->stream->read ($messageSize, true);
The Read method core code 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->rec Vtimeoutsec, $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); }
Use this while loop to splice information. The point is that the $chunk that fread out contains garbled characters.
Call Master!
Consumer should only be able to determine if the broker has changed through a loop, and then update it.