执行:composer install 时,提示:enqueue/rdkafka 0.10.19 requires ext-rdkafka -> it is missing from your system. Install or enable PHP’s rdkafka extension.

1、执行:composer install 时,提示:enqueue/rdkafka 0.10.19 requires ext-rdkafka -> it is missing from your system. Install or enable PHP’s rdkafka extension.。如图1

图1

PS E:\wwwroot\object> composer install
Installing dependencies from lock file (including require-dev)
Verifying lock file contents can be installed on current platform.
Your lock file does not contain a compatible set of packages. Please run composer update.

  Problem 1
    - enqueue/rdkafka is locked to version 0.10.19 and an update of this package was not requested.
    - enqueue/rdkafka 0.10.19 requires ext-rdkafka ^4.0|^5.0|^6.0 -> it is missing from your system. Install or enable PHP's rdkafka extension.

To enable extensions, verify that they are enabled in your .ini files:
    - C:\php-7.4.27\php.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-rdkafka` to temporarily ignore these required extensions.

2、决定启用 PHP 的 rdkafka 扩展。打开:https://pecl.php.net/package/rdkafka/6.0.1/windows ,下载 7.4 Thread Safe (TS) x64。解压缩 php_rdkafka-6.0.1-7.4-ts-vc15-x64 后,将 php_rdkafka.dll 复制至:C:\php-7.4.27\ext\php_rdkafka.dll。然后编辑 php.ini,添加 extension=rdkafka

3、重新启动 PHP 时,报错:PHP Warning: PHP Startup: Unable to load dynamic library ‘rdkafka’。如图2

图2

PS C:\Users\Lenovo> php-cgi.exe -b 127.0.0.1:9000-c C:/php-7.4.27/php.ini
PHP Warning:  PHP Startup: Unable to load dynamic library 'rdkafka' (tried: C:/php-7.4.27/ext\rdkafka (鎵句笉鍒版寚瀹氱殑妯″潡銆?, C:/php-7.4.27/ext\php_rdkafka.dll (鎵句 笉鍒版寚瀹氱殑妯″潡銆?) in Unknown on line 0
<br />
<b>Warning</b>:  PHP Startup: Unable to load dynamic library 'rdkafka' (tried: C:/php-7.4.27/ext\rdkafka (鎵句笉鍒版寚瀹氱殑妯″潡銆?, C:/php-7.4.27/ext\php_rdkafka.dll (鎵句笉鍒版寚瀹氱殑妯″潡銆?) in <b>Unknown</b> on line <b>0</b><br />

4、参考:https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka.installation.windows.html Installing the rdkafka extension on Windows。将 librdkafka.dll 放入 PHP 根目录(与 php.exe 同一级别),将 php_rdkfaka.dll 文件放入 PHP 扩展目录(默认为“ext”)。将 librdkafka.dll 复制至:C:\php-7.4.27\librdkafka.dll。重新启动 PHP 时,不再报错。

5、查看 phpinfo,搜索:rdkafka,PHP 的 rdkafka 扩展已经启用成功。如图3

图3

6、执行:composer install 时,不再提示,运行正常。如图4

图4

永夜