0

I encounter an error using https://github.com/arnaud-lb/php-rdkafka

I followed the installation but still encounter an error using the class.

Installation process:

- sudo apt install php-pear

- sudo apt-get install -y librdkafka-dev

- sudo pecl install rdkafka

Enable PHP-extension in PHP config. Add to php.ini

sudo nano /etc/php/7.4/cli/php.ini

extension=rdkafka.so

Restart apache server

sudo service apache2 restart

Code :

    $conf = new \RdKafka\Conf();
    $conf->set('log_level', (string) LOG_DEBUG);
    $conf->set('debug', 'all');
    $rk = new \RdKafka\Producer($conf);
    $rk->addBrokers("10.0.0.1:9092,10.0.0.2:9092");

Composer.json

  "require": {
    "php": "^7.4",
    "ext-rdkafka": "*",
    ...

Error:

"Class 'RdKafka\\Conf' not found"

What's wrong with my installation? why RdKafka\Conf class not found?

Kenneth
  • 2,813
  • 3
  • 22
  • 46
  • Did you check whether the extension was **really** enabled, for example through checking this in `phpinfo`? Also, how is this problem related to Laravel? – Nico Haase Nov 21 '22 at 20:55
  • @NicoHaase oh! when I run this command `php -m` I saw the extension but when I add this code in php `dd(get_loaded_extensions());` I cannot see the rdkafka extension. How to solve this? – Kenneth Nov 21 '22 at 21:00
  • 2
    @Kenneth Did you check that the extension is enabled in both FPM and CLI php configuration files (yes there are two, one for command line and the other for the service) OR maybe the PHP process did not restart with the restart of apache. try restarting it directly. – N69S Nov 21 '22 at 21:06
  • @N69S I restarted the apache and my laptop. But FPM did not load the rdkafka extension – Kenneth Nov 21 '22 at 21:14
  • you need to enable rdkafka in php.ini that is loaded by apache.. check using `phpinfo` to get the path of php.ini – dann Nov 22 '22 at 03:02

0 Answers0