php-rdkafka 扩展 常见问题

最近项目开发中需要使用 Kafka 消息队列。经过检索,PHP下面有通用的两种方式来调用 Kafka 。

php-rdkafka 扩展
以 PHP 扩展的形式进行使用是非常高效的。另外,该项目也提供了非常完备的 文档 。

不过在 Mac 环境中安装的过程中出现了以下报错:


$ sudo pecl install rdkafka

checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking for rdkafka support... yes, shared
checking for librdkafka/rdkafka.h" in default path... not found
configure: error: Please reinstall the rdkafka distribution

开始以为是因为 pecl 安装缺少了一些依赖。然后使用了源码编译的方式进行安装:


$ git clone https://github.com/arnaud-lb/php-rdkafka.git
$ cd php-rdkafka
$ phpize
$ ./configure
$ make all -j 5

....
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk is broken... no
checking for rdkafka support... yes, shared
checking for librdkafka/rdkafka.h" in default path... not found
configure: error: Please reinstall the rdkafka distribution
同样报错了。后来仔细看文档才发现。这里有一个依赖:librdkafka 。

然后安装它:


$ git clone https://github.com/edenhill/librdkafka.git
$ cd librdkafka
$ ./configure
$ make && make install

再执行 sudo pecl install rdkafka ,执行OK。

然后将 rdkafka.so 添加到相应的 /path/to/php.ini 的末尾即可。

执行 php -m | grep rdkafka ,验证是否添加完成。

猜你喜欢

转载自blog.csdn.net/oqzuser12345678999q/article/details/107562949