最近项目开发中须要使用 Kafka
消息队列。通过检索,PHP下面有通用的两种方式来调用 Kafka
。php
以 PHP 扩展的形式进行使用是很是高效的。另外,该项目也提供了很是完备的 文档 。html
不过在 Mac 环境中安装的过程当中出现了如下报错:git
$ 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
安装缺乏了一些依赖。而后使用了源码编译的方式进行安装:github
$ 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 。code
而后安装它:htm
$ 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
的末尾便可。pdo
执行 php -m | grep rdkafka
,验证是否添加完成。开发
Kafka-php 使用纯粹的 PHP 编写的 Kafka
客户端,目前支持 0.8.x
以上版本的 Kafka
。因为使用 PHP 语言编写因此不用编译任何的扩展就能够使用,下降了接入与维护成本。文档