Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does PHP extend the kafka installation application

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about how to expand the kafka installation application of PHP. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

one。 First make sure that jdk is installed.

Use the command

[root@localhost] # java-versionjava version "1.8.0y73" Java (TM) SE Runtime Environment (build 1.8.0_73-b02) Java HotSpot (TM) 64-Bit Server VM (build 25.73-b02, mixed mode)

If you have the above information, install it down. some of the jdk may not match, so install it on the right one. If you don't have an installation, take a look at the following jdk installation method:

Http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

Download the jdk8 version from this address. I downloaded jdk-8u73-linux-x64.tar.gz and unzipped it to / usr/local/jdk/.

Then open the / etc/profile file

[root@localhost ~] # vim / etc/profile

Write the following code in the file

Export JAVA_HOME=/usr/local/jdk/jdk1.8.0_73export CLASSPATH=.:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$JAVA_HOME/bin:$PATH

Last

[root@localhost ~] # source / etc/profile

At this point, jdk takes effect and can be verified using java-version.

two。 Next install Kafka

1. Download Kafka

Go to http://kafka.apache.org/downloads.html to download the corresponding version, I use kafka_2.9.1-0.8.2.2.tgz.

two。 Download and unzip it to your favorite directory

I am decompressing to / usr/local/kafka/kafka_2.9.1-0.8.2.2

3. Run the default Kafka

Start Zookeeper server

[root@localhost kafka_2.9.1-0.8.2.2] # sh bin/zookeeper-server-start.sh config/zookeeper.properties &

Start Kafka server

[root@localhost kafka_2.9.1-0.8.2.2] # sh bin/kafka-server-start.sh config/server.properties &

Run producer producer

[root@localhost kafka_2.9.1-0.8.2.2] # sh bin/kafka-console-producer.sh-broker-list localhost:9092-topic test

Run Consumer consumer

[root@localhost kafka_2.9.1-0.8.2.2] # sh bin/kafka-console-consumer.sh-zookeeper localhost:2181-topic test-from-beginning

In this way, enter the content on the producer side, and the consumer will receive it immediately.

4. When there is a cross-machine producer or consumer connection

The host.name of config/server.properties needs to be configured, otherwise the cross-machine connection will not be connected.

three。 Kafka-PHP extension

After using it for one lap, https://github.com/nmred/kafka-php can be used.

I installed it using composer, and here is an example:

Producer.php

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report