OSX-Ask the gods: How do you connect Kafka with PHP clients, and how do you monitor broker changes to refresh client data?

Source: Internet
Author: User
Tags fread
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.

  • 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.