php操作kafka需要安装rdkafka扩展,而rdkafka又依赖librdkafka库,因此在安装rdkafka之前,需要先安装librdkafka,之后就可以与kafka服务进行交互了。
1、安装 librdkafka 库
git clone https://github.com/confluentinc/librdkafka.git cd librdkafka. /configure make && make install
2、安装 php-kafka(rdkafka) 扩展
git clone https://github.com/arnaud-lb/php-rdkafka.git cd php-rdkafka /usr/local/opt/php@7.4/bin/phpize ./configure --with-php-config=/usr/local/opt/php@7.4/bin/php-config make && make install
如图:
3、 在php.ini 文件中加入rdkafka扩展
sudo vim /usr/local/etc/php/7.4/php.ini extension=/usr/local/lib/php/pecl/20190902/rdkafka.so
4、重启php74
brew services restart php@7.4