PHP Error on module installation

Created on 5 October 2023, 9 months ago
Updated 11 October 2023, 9 months ago

Under php8.1 drupal 10.1 project, installing this module drush en kafka gives an error:

[error] TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 134 of /var/www/html/web/modules/contrib/kafka/src/ClientFactory.php) #0 /var/www/html/web/modules/contrib/kafka/src/ClientFactory.php(134): implode(',', NULL)

I added an array in the implode and it was ok for the install
I guess default install config syntax is wrong or something no more php8.1 compatible

šŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡«šŸ‡·France louis-cuny

Live updates comments and jobs are added and updated live.
  • PHP 8.1

    The issue particularly affects sites running on PHP version 8.1.0 or later.

Sign in to follow issues

Comments & Activities

  • Issue created by @louis-cuny
  • Status changed to Postponed: needs info 9 months ago
  • šŸ‡«šŸ‡·France fgm Paris, France

    That looks like a settings issue more than a bug. Can you show the part of your settings files concerned with Kafka, redacting credentials if any exist ?

  • Status changed to Active 9 months ago
  • šŸ‡«šŸ‡·France louis-cuny

    This happens on "drush en kafka", so the default configuration should be correct. I usually set the configurations after the modules are installed

    I didn't do anything else than composer require and drush en (excepting insatlling rdkafka)

  • šŸ‡¬šŸ‡§United Kingdom astoker88

    @louis i noticed you have tagged this issue under the dev branch?

    https://www.drupal.org/project/kafka/issues/3318381 šŸ“Œ Bump ext-rdkafka dependency for PHP 8.1 and D10 compatibility Needs work - I raised this some time ago, and in the end ended up forking the branch and using a custom version of the module so that we could upgrade to PHP8.1.

    Worth trying with these settings.

    @fgm - i see your again active, can we work together to get a new release of this module out? Would love to get back to using your contrib version.

  • šŸ‡¬šŸ‡§United Kingdom astoker88

    @louis - also please see a working config:

    // Kafka config
    $brokers = [
    'broker-9092',
    'broker1-9092',
    'broker2-9092',
    ];
    $settings['kafka'] = [
    'topic' => 'topic1',
    'topic2' => 'topic2',
    'consumer' => [
    'brokers' => $brokers,
    ],
    'producer' => [
    'brokers' => $brokers,
    'conf' => [
    'acks' => '1',
    'metadata.broker.list' => implode( ',', $brokers),
    'linger.ms' => '1000',
    ],
    ],
    ];

  • šŸ‡«šŸ‡·France fgm Paris, France

    @astoker88 just passing by :-). But if you finalize the patch for šŸ“Œ Bump ext-rdkafka dependency for PHP 8.1 and D10 compatibility Needs work I could review it. Still no client work on Kafka for Drupal so I won't be spending much time on this.

    Regarding @louis-cuny's case, I suppose his "brokers" key is a string instead of an array indeed, hence the question.

    @louis-cuny The module contains an example.settings.local.php with the correct format, which needs to be set before enabling the module.

  • šŸ‡«šŸ‡·France louis-cuny

    I got some precisions

    I'm using -beta1 version + https://www.drupal.org/project/kafka/issues/3318381 šŸ“Œ Bump ext-rdkafka dependency for PHP 8.1 and D10 compatibility Needs work patch
    I understand I need to update my configurations.

    This issue is more about having this error so soon in the installation. I guess it would be better to let users install the module with the default configuration proposed in config/install
    And later throw errors or show messages in status page for example

  • šŸ‡¬šŸ‡§United Kingdom astoker88

    @louis ok Iā€™m going to reroll the patch for 8.1 functionality , and as part of that review the default config and install too.

  • šŸ‡«šŸ‡·France louis-cuny

    I think my installation has another issue
    There is something strange, in ClientFactory.php for example, it's requiering a class Producer

    use RdKafka\Producer;

    Like if it would be some other composer package required. There is no package listed in the composer.json of the module
    Or it's just Phpstorm that doesn't see php-extension classes ?

    Some info about rdkafka extension I have installed:
    rdkafka support enabled
    version 6.0.3
    build date Oct 5 2023 13:43:25
    librdkafka version (runtime) 1.6.0
    librdkafka version (build) 1.6.0.255

    PHP Version 8.1.22

    If I'm correct, these informations from phpinfo page are saying I have required librdkafka and rdkafka php extension ?

    I am confused about librdkafka that is no more https://github.com/edenhill/librdkafka
    But https://github.com/confluentinc/librdkafka. I guess it's the same, but no php client

  • šŸ‡«šŸ‡·France fgm Paris, France

    Not sure we can easily fix this: when an error is in the settings, it means it is in code which runs pretty much before any module logic.

    Do you confirm the error goes away when the settings format is correct ?

    Would it be better to just throw an exception or a die() when settings are not as expected ? The downside, of course, being that the check has to run on each succesful hit too.

  • šŸ‡«šŸ‡·France louis-cuny

    Actually, I don't understand the config in kafka/config/install.
    It seems to not be used at all in the module. Can you confirm please?

    If so, it's not related to the error, it would mean than only settings are used. But in the readme it says that settings should be set up after module installation.

    I will try to restart the installation later

    I suspect also something is wrong with composer requirements. Because of the current rdkafka ^5 requirement, I had to use --ignore-platform-reqs on installation (I'm using 6.0.3)

  • šŸ‡«šŸ‡·France fgm Paris, France

    Indeed, AFAICS that config is not used at all and should be removed : everything comes from settings.

    Regarding the README, I think I see why it is not clear: it says "install the module as usual", and that means "do a composer require / composer install", it does not mean "enable" the module: that should be done after creating the settings.

  • šŸ‡«šŸ‡·France louis-cuny

    Adding the settings could also be done before composer require, maybe it would avoid any confusion
    I guess some users are still going to try to install and enable it before writting the settings
    Maybe we should do some check to avoid the installation if settings are breaking the module

  • @louis-cuny opened merge request.
  • Status changed to Needs review 9 months ago
Production build 0.69.0 2024