最近项目开发需要用到Kafka消息队列。搜索了一下,PHP下调用Kafka的常用方式有两种。php-rdkafka扩展作为PHP扩展非常有效。此外,该项目还提供了非常完整的文档。但是在Mac环境下安装时出现如下错误:$sudopeclinstallrdkafkacheckingforre2c...noconfigure:WARNING:Youwillneedre2c0.13.4orlaterifyouwanttoregeneratePHPparsers.checkingforgawk...nocheckingfornawk...nocheckingforawk...awkcheckingifawkisbroken...nocheckingforrdkafkasupport...yes,sharedcheckingforlibrdkafka/rdkafka.h"indefaultpath...notfoundconfigure:error:请重新安装rdkafka发行版,起初以为是因为pecl安装缺少一些依赖项。然后使用源码编译方式安装:$gitclonehttps://github.com/arnaud-lb/php-rdkafka.git$cdphp-rdkafka$phpize$./configure$makeall-j5....checkingforre2c...noconfigure:WARNING:如果您想重新生成PHP解析器,您将需要re2c0.13.4或更高版本。正在检查gawk...nocheckingfornawk...nocheckingforawk...awkcheckingifawkisbroken...nocheckingforrdkafkasupport...yes,sharedcheckingforlibrdkafka/rdkafka.h"indefaultpath...notfoundconfigure:error:Pleasereinstalltherdkafkadistribution也报错,仔细看后发现文档。这里有一个依赖:librdkafka。然后安装它:$gitclonehttps://github.com/edenhill/librdkafka.git$cdlibrdkafka$./configure$make&&makeinstall然后执行sudopeclinstallrdkafka,执行OK.然后rdkafka在对应的/path/to/php.ini末尾添加.so即可.执行php-m|greprdkafka验证是否添加完成.kafka-php扩展包Kafka-php使用纯PHP编写的Kafka客户端。目前支持Kafka0.8.x以上版本。由于使用PHP语言编写,无需编译任何扩展即可使用,降低了接入和维护成本。
