Giter VIP home page Giter VIP logo

hyperf-docker's Introduction

hyperf-docker

Supported tags and respective Dockerfile links

tag format:

  • 8.1: php version, support 8.1/8.2/8.3, Recommend 8.1
  • alpine: base images, supoort alpine/ubuntu, recommend alpine
  • v3.18: alpine version, support alpine 3.16/3.17/3.18/edge, recommend 3.18
  • swoole: support base/dev/swoole/swow
  • v5.1.2: swoole/swow version

support:

Quick reference

How to use this image

Added Dockerfile to your project.

Info

Base image contains extensions below:

[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
gd
hash
iconv
igbinary
json
libxml
mbstring
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
redis
Reflection
session
SimpleXML
sockets
sodium
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib

[Zend Modules]
Zend OPcache

The Swoole info like the code below:

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.1.1
Built => Dec 11 2023 01:47:26
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 3.1.4 24 Oct 2023
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
c-ares => 1.19.1
zlib => 1.2.13
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled
coroutine_pgsql => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

more demo

PHP 8.x

For PHP 8.x you have to install $PHPIZE_DEPS and use pecl8 instead of pecl.

  • grpc
RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl8 install grpc \
&& echo "extension=grpc.so" > /etc/php8/conf.d/grpc.ini

PHP 7.x

  • kafka
RUN apk add --no-cache librdkafka-dev \
&& pecl install rdkafka \
&& echo "extension=rdkafka.so" > /etc/php7/conf.d/rdkafka.ini
RUN apk add --no-cache openssl-dev \
&& pecl install mongodb \
&& echo "extension=mongodb.so" > /etc/php7/conf.d/mongodb.ini
  • protobuf
# mac protobuf: https://blog.csdn.net/JoeBlackzqq/article/details/83118248
RUN apk add --no-cache protobuf \
&& cd /tmp \
&& pecl install protobuf \
&& echo "extension=protobuf.so" > /etc/php7/conf.d/protobuf.ini
  • swoole tracker
# download swoole tracker
ADD ./swoole-tracker-install.sh /tmp

RUN chmod +x /tmp/swoole-tracker-install.sh \
&& cd /tmp \
&& ./swoole-tracker-install.sh \
&& rm /tmp/swoole-tracker-install.sh \
# config
&& cp /tmp/swoole-tracker/swoole_tracker72.so /usr/lib/php7/modules/swoole_tracker72.so \
&& echo "extension=swoole_tracker72.so" > /etc/php7/conf.d/swoole-tracker.ini \
&& echo "apm.enable=1" >> /etc/php7/conf.d/swoole-tracker.ini \
&& echo "apm.sampling_rate=100" >> /etc/php7/conf.d/swoole-tracker.ini \
&& echo "apm.enable_memcheck=1" >> /etc/php7/conf.d/swoole-tracker.ini \
# launch
&& printf '#!/bin/sh\n/opt/swoole/script/php/swoole_php /opt/swoole/node-agent/src/node.php' > /opt/swoole/entrypoint.sh \
&& chmod 755 /opt/swoole/entrypoint.sh
  • fix aliyun oss wrong charset
# fix aliyun oss wrong charset: https://github.com/aliyun/aliyun-oss-php-sdk/issues/101
# https://github.com/docker-library/php/issues/240#issuecomment-762438977

RUN apk --no-cache --allow-untrusted --repository http://dl-cdn.alpinelinux.org/alpine/edge/community/ add gnu-libiconv=1.15-r2
ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so

hyperf-docker's People

Contributors

assert6 avatar daydaygo avatar deminy avatar jyil avatar leocavalcante avatar limingxinleo avatar sy-records avatar tw2066 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hyperf-docker's Issues

Build will be failed for PHP 8.1 - alpine 3.16 - swoole 5.0.2 due to no php command.

Build alpine-swoole will be failed for PHP 8.1 - alpine 3.16 - swoole 5.0.2 due to no php command.

Executed command:

docker compose build alpine-swool

.env

COMPOSER_VERSION=2.5.4

PHP_VERSION=8.1
PHP_BUILD_VERSION=8
ALPINE_VERSION=3.16
SW_VERSION=v5.0.2

Related source code

https://github.com/hyperf/hyperf-docker/blob/master/8.1/alpine/swoole/Dockerfile#L59-L62

Solution

If change php -> php81 , may it works.
May we can try to add execution file name as environment variable to build docker image.

RUN php81 -v & sleep 3 \
    && php81 -m & sleep 3 \
    && php81 --ri swoole & sleep 3 \
    && php81 --ri Zend\ OPcache & sleep 3 \
    && composer & sleep 3 \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

Windows的WLS2下,无法拉取镜像

PS D:\workdir> docker pull hyperf/8.0-alpine-v3.12-base
Using default tag: latest
Error response from daemon: pull access denied for hyperf/8.0-alpine-v3.12-base, repository does not exist or may require 'docker login': denied: requested access to the resource is denied

====================================
docker已经登录,正常使用

mac环境:
➜ swoole git:(master) ✗ docker run --rm hyperf/hyperf:8.1-alpine-v3.15-base /usr/bin/php -m
PHP Warning: PHP Startup: Unable to load dynamic library 'igbinary' (tried: /usr/lib/php8/modules/igbinary (Error loading shared library /usr/lib/php8/modules/igbinary: No such file or directory), /usr/lib/php8/modules/igbinary.so (Error relocating /usr/lib/php8/modules/igbinary.so: zend_class_serialize_deny: symbol not found)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'redis' (tried: /usr/lib/php8/modules/redis (Error loading shared library /usr/lib/php8/modules/redis: No such file or directory), /usr/lib/php8/modules/redis.so (Error relocating /usr/lib/php8/modules/redis.so: igbinary_unserialize: symbol not found)) in Unknown on line 0
[PHP Modules]

docker安装hyperf开发环境默认内存不足。

docker run -v /tmp/skeleton:/hyperf-skeleton -p 9501:9501 -it --entrypoint /bin/sh hyperf/hyperf:7.2-alpine-cli
这样默认安装的php在内存分配上不够,hyperf项目的类多了之后就直接启动不起来,能否改善一下,在docker安装hyperf开发环境的时候就默认设置一下php内存,不用每次都去调或者每次都修改php文件手动设置内存分配。

安装rdkafka扩展时 pecl not found

docker run --name hyperf
--privileged -u root
--entrypoint /bin/sh
hyperf/hyperf:7.4-alpine-v3.11-swoole

apk add --no-cache librdkafka-dev
&& pecl install rdkafka
&& echo "extension=rdkafka.so" > /etc/php7/conf.d/rdkafka.ini

1638515084(1)

hyperf/hyperf:8.1-alpine-v3.15-swoole-v4.8.6新建项目报错

composer create-project hyperf/hyperf-skeleton

报错

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires hyperf/redis ~2.2.0 -> satisfiable by hyperf/redis[v2.2.0-beta1, ..., 2.2.x-dev].
    - hyperf/redis[v2.2.0-beta1, ..., 2.2.x-dev] require ext-redis * -> it is missing from your system. Install or enable PHP's redis extension.

输入php -v出现警告

PHP Warning:  PHP Startup: Unable to load dynamic library 'igbinary' (tried: /usr/lib/php8/modules/igbinary (Error loading shared library /usr/lib/php8/modules/igbinary: No such file or directory), /usr/lib/php8/modules/igbinary.so (Error relocating /usr/lib/php8/modules/igbinary.so: zend_class_serialize_deny: symbol not found)) in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library 'redis' (tried: /usr/lib/php8/modules/redis (Error loading shared library /usr/lib/php8/modules/redis: No such file or directory), /usr/lib/php8/modules/redi

构建出问题

[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Di\Listener\BootApplicationListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Config\Listener\RegisterPropertyHandlerListener listener.
[DEBUG] Event Hyperf\Framework\Event\BootApplication handled by Hyperf\Paginator\Listener\PageResolverListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booting handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
[DEBUG] Event Hyperf\Database\Model\Events\Booted handled by Hyperf\DbConnection\Listener\ModelEventListener listener.
Proxy class create success.
The command '/bin/sh -c composer install --no-dev && composer dump-autoload -o && mv .env.${APP_ENV} .env && php /opt/www/bin/hyperf.php di:init-proxy' returned a non-zero code: 1

FROM hyperf/hyperf:7.3-alpine-cli

如果改为hyperf/hyperf:7.2-alpine-cli构建正常

构建的时候出问题了呢

The command '/bin/sh -c composer install --no-dev && composer dump-autoload -o && php /opt/www/bin/hyperf.php di:init-proxy' returned a non-zero code: 1

Mac M1下报错了

Mac OS Sonoma 14.2.1

Docker Desktop v4.28.0

镜像: hyperf/hyperf:8.1-alpine-v3.18-swow

211708997613_ pic

没有Zlib依赖

镜像版本 hyperf:7.4-alpine-v3.12-swoole

看到Dockerfile里面有add php7-zlib 但实际上没有安装成功

底包不支持 iconv()

Notice: iconv(): Wrong charset, conversion from GBK' to UTF-8//IGNORE' is not allowed

这个不支持此函数

Class 'Swoole\Coroutine\PostgreSql

您好,請問您是否有遇過此問題,Class 'Swoole\Coroutine\PostgreSql,您是怎麼解決的呢,我有嘗試再image裡抓下 ext-PostgreSql 仍然報錯,麻煩您了

8.0/alpine/swoole/Dockerfile有错,build报错

1, 第10行:
FROM hyperf/hyperf:8.0-alpine-v${ALPINE_VERSION}-base
${ALPINE_VERSION} 变量读取不到,当运行 docker build -f Dockerfile . 时会报错:
failed to solve with frontend dockerfile.v0: failed to create LLB definition: docker.io/hyperf/hyperf:8.0-alpine-v-base: not found

2,当手动修改Dockerfile中的${ALPINE_VERSION}为具体版本如 3.14时,则可以执行。

使用hyperf/hyperf:7.4-alpine-v3.9-cli版本时,使用easywechat发送外部请求会有问题

使用hyperf/hyperf:7.4-alpine-v3.9-cli版本做底包的时候
在docker容器内发送外部请求会将请求结果打印在终端上,但是php代码是无法获取到返回值
我们在使用easywechat的时候发现的
是因为这个版本的swoole是4.5.5的,swoolle4.5.6以后才修复的
我们将底包升为hyperf/hyperf:7.4-alpine-v3.10-swoole-v4.6.3,则代码发送外部请求的时候,不会将讲过打印到终端,
php代码也能获取到返回值了

请问,哪个版本支持swow 1.4.0

hyperf/hyperf:8.1-alpine-v3.16-swow
hyperf/hyperf:8.1-alpine-v3.17-swow
hyperf/hyperf:8.1-alpine-v3.18-swow
这些镜像挨个试过来了。都是swow1.3.1. 目前hyperf/swow-skeleton需要 swow 1.4.0。该如何处理?

image

pecl8: command not found

Hello, I tried to install package opentelemetry without success.

The pecl extension was not found.

I tried following the manual with the following commands:

RUN apk add --no-cache $PHPIZE_DEPS \
&& pecl8 install opentelemetry

With the following return:

bash-5.1# apk add --no-cache $PHPIZE_DEPS \
&& pecl8 install opentelemetry
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
OK: 318 MiB in 147 packages
bash: pecl8: command not found
bash-5.1# 

How to correctly install pecl?

Tks!

config-nacos组件在解析nacos里面yaml数据报错

Execute the command and paste the result below.

Command: uname -a && php -v && composer info | grep hyperf && php --ri swoole

bash-5.0# uname -a && php -v && composer info | grep hyperf && php --ri swoole
Linux 1976dff90a1f 4.15.0-128-generic #131-Ubuntu SMP Wed Dec 9 06:57:35 UTC 2020 x86_64 Linux
PHP 7.4.21 (cli) (built: Jul  4 2021 16:41:27) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies
hyperf/cache                         v2.2.0  A cache component for hyperf.
hyperf/command                       v2.2.0  Command for hyperf
hyperf/config                        v2.2.0  An independent component that provides configuration container.
hyperf/config-center                 v2.2.0  The abstraction component of config center
hyperf/config-nacos                  v2.2.0  A nacos adapter for config center component.
hyperf/constants                     v2.2.0  A constants component for hyperf.
hyperf/consul                        v2.2.0  A Consul Client for Hyperf.
hyperf/contract                      v2.2.0  The contracts of Hyperf.
hyperf/database                      v2.2.0  A flexible database library.
hyperf/db-connection                 v2.2.0  A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v2.2.0  A Devtool for Hyperf.
hyperf/di                            v2.2.1  A DI for Hyperf.
hyperf/dispatcher                    v2.2.0  A HTTP Server for Hyperf.
hyperf/engine                        v1.1.6 
hyperf/event                         v2.2.0  an event manager that implements PSR-14.
hyperf/exception-handler             v2.2.0  Exception handler for hyperf
hyperf/framework                     v2.2.0  A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                        v2.2.0  Swoole coroutine handler for guzzle
hyperf/http-message                  v2.2.0  microservice framework base on swoole
hyperf/http-server                   v2.2.1  A HTTP Server for Hyperf.
hyperf/ide-helper                    v2.2.0  IDE help files for Hyperf.
hyperf/json-rpc                      v2.2.0  A JSON RPC component for Hyperf RPC Server or Client.
hyperf/load-balancer                 v2.2.0  A load balancer library for Hyperf.
hyperf/logger                        v2.2.0  A logger component for hyperf.
hyperf/memory                        v2.2.0  An independent component that use to operate and manage memory.
hyperf/model-listener                v2.2.0  A model listener for Hyperf.
hyperf/nacos                         v2.2.0  Nacos SDK
hyperf/pool                          v2.2.0  An independent universal connection pool component.
hyperf/process                       v2.2.0  A process component for hyperf.
hyperf/redis                         v2.2.0  A redis component for hyperf.
hyperf/rpc                           v2.2.0  A rpc basic library for Hyperf.
hyperf/rpc-client                    v2.2.0  An abstract rpc server component for Hyperf.
hyperf/rpc-server                    v2.2.0  An abstract rpc server component for Hyperf.
hyperf/server                        v2.2.0  A base server library for Hyperf.
hyperf/service-governance            v2.2.0  A service governance component for Hyperf.
hyperf/service-governance-nacos      v2.2.2  A nacos adapter for service governance.
hyperf/testing                       v2.2.0  Testing for hyperf
hyperf/utils                         v2.2.0  A tools package that could help developer solved the problem quickly.

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.7.0
Built => Jul 24 2021 00:10:22
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1k  25 Mar 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608

Description:

使用的docker镜像:hyperf/hyperf:7.4-alpine-v3.12-swoole
config-nacos组件在解析nacos里面yaml数据报错

[ERROR] Error: Call to undefined function Hyperf\ConfigNacos\yaml_parse()(0) in /xx/vendor/hyperf/config-nacos/src/Client.php:85
Stack trace:
#0 /xx/vendor/hyperf/config-nacos/src/Client.php(67): Hyperf\ConfigNacos\Client->decode()
#1 /xx/vendor/hyperf/config-center/src/AbstractDriver.php(132): Hyperf\ConfigNacos\Client->pull()
#2 /xx/vendor/hyperf/config-center/src/AbstractDriver.php(100): Hyperf\ConfigCenter\AbstractDriver->pull()
#3 /xx/vendor/hyperf/config-center/src/Listener/FetchConfigOnBootListener.php(34): Hyperf\ConfigCenter\AbstractDriver->fetchConfig()
#4 /xx/vendor/hyperf/event/src/EventDispatcher.php(48): Hyperf\ConfigCenter\Listener\FetchConfigOnBootListener->process()
#5 /xx/vendor/hyperf/process/src/AbstractProcess.php(127): Hyperf\Event\EventDispatcher->dispatch()
#6 {main}
[INFO] Process[config-center-fetcher.0] stopped.

Steps To Reproduce:

var_dump(function_exitsts('yaml_parse'));

打印的结果是:false

config_center.php配置:

'nacos' => [
    'driver' => Hyperf\ConfigNacos\NacosDriver::class,
    'merge_mode' => Hyperf\ConfigNacos\Constants::CONFIG_MERGE_OVERWRITE,
    'interval' => 3,
    'default_key' => 'nacos_config',
    'listener_config' => [
        // dataId, group, tenant, type, content
        'nacos_config' => [
            'tenant'    => 'tenant',
            'data_id'   => 'redis',
            'group'     => 'ii',
            'type'      => 'yml',
        ],
        'nacos_config.data' => [
            'data_id'   => 'hyperf-service-config-yml',
            'group'     => 'DEFAULT_GROUP',
            'type'      => 'yml',
        ],
    ],
],

Fatal error: Uncaught longlang\phpkafka\Exception\KafkaErrorException

PHP Warning:  unpack(): Type l: not enough input, need 4, have 0 in /www/vendor/longlang/phpkafka/src/Protocol/Type/Int32.php on line 43

Warning: unpack(): Type l: not enough input, need 4, have 0 in /www/vendor/longlang/phpkafka/src/Protocol/Type/Int32.php on line 43
PHP Fatal error:  Uncaught longlang\phpkafka\Exception\KafkaErrorException: [35] The version of API is not supported. in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php:385
Stack trace:
#0 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(190): longlang\phpkafka\Protocol\ErrorCode::check()
#1 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(98): longlang\phpkafka\Client\SyncClient->updateApiVersions()
#2 /www/vendor/longlang/phpkafka/src/Client/SwooleClient.php(52): longlang\phpkafka\Client\SyncClient->connect()
#3 /www/vendor/longlang/phpkafka/src/Broker.php(88): longlang\phpkafka\Client\SwooleClient->connect()
#4 /www/vendor/longlang/phpkafka/src/Producer/Producer.php(39): longlang\phpkafka\Broker->updateBrokers()
#5 /www/vendor/hyperf/kafka/src/Producer.php(173): longlang\phpkafka\Producer\Producer->__construct()
#6 /www/vendor/hyperf/kafka/src/Producer.php(137): Hyperf\Kafka\Producer->makeProducer()
#7 {main}
  thrown in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php on line 385

Fatal error: Uncaught longlang\phpkafka\Exception\KafkaErrorException: [35] The version of API is not supported. in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php:385
Stack trace:
#0 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(190): longlang\phpkafka\Protocol\ErrorCode::check()
#1 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(98): longlang\phpkafka\Client\SyncClient->updateApiVersions()
#2 /www/vendor/longlang/phpkafka/src/Client/SwooleClient.php(52): longlang\phpkafka\Client\SyncClient->connect()
#3 /www/vendor/longlang/phpkafka/src/Broker.php(88): longlang\phpkafka\Client\SwooleClient->connect()
#4 /www/vendor/longlang/phpkafka/src/Producer/Producer.php(39): longlang\phpkafka\Broker->updateBrokers()
#5 /www/vendor/hyperf/kafka/src/Producer.php(173): longlang\phpkafka\Producer\Producer->__construct()
#6 /www/vendor/hyperf/kafka/src/Producer.php(137): Hyperf\Kafka\Producer->makeProducer()
#7 {main}
  thrown in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php on line 385
[2021-09-02 02:58:02 *753.1]	ERROR	php_swoole_server_rshutdown() (ERRNO 503): Fatal error: Uncaught longlang\phpkafka\Exception\KafkaErrorException: [35] The version of API is not supported. in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php:385
Stack trace:
#0 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(190): longlang\phpkafka\Protocol\ErrorCode::check()
#1 /www/vendor/longlang/phpkafka/src/Client/SyncClient.php(98): longlang\phpkafka\Client\SyncClient->updateApiVersions()
#2 /www/vendor/longlang/phpkafka/src/Client/SwooleClient.php(52): longlang\phpkafka\Client\SyncClient->connect()
#3 /www/vendor/longlang/phpkafka/src/Broker.php(88): longlang\phpkafka\Client\SwooleClient->connect()
#4 /www/vendor/longlang/phpkafka/src/Producer/Producer.php(39): longlang\phpkafka\Broker->updateBrokers()
#5 /www/vendor/hyperf/kafka/src/Producer.php(173): longlang\phpkafka\Producer\Producer->__construct()
#6 /www/vendor/hyperf/kafka/src/Producer.php(137): Hyperf\Kafka\Producer->makeProducer()
#7 {main}
  thrown in /www/vendor/longlang/phpkafka/src/Protocol/ErrorCode.php on line 385

其中,“The version of API is not supported.”指明phpkafka不支持,不晓得需要什么具体的版本?

Kafka 环境是自建还是云服务?
根据Hypef-2.1手册,使用Docker的hyperf/hyperf:7.4-alpine-v3.13-swoole 镜像建立的容器

环境信息:

bash-5.1# php -v & php --ri swoole & composer info | grep longlang/phpkafka
[1] 777
[2] 778
PHP 7.4.23 (cli) (built: Aug 26 2021 23:05:01) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 4.7.0
Built => Aug 28 2021 09:20:30
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1l  24 Aug 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
longlang/phpkafka                    v1.1.5  A kafka client. Support php-fpm and Swoole.
[1]-  Done                    php -v
[2]+  Done                    php --ri swoole

bash-5.1# php -ir | grep kafka
/etc/php7/conf.d/rdkafka.ini
rdkafka
rdkafka support => enabled
librdkafka version (runtime) => 1.7.0
librdkafka version (build) => 1.7.0.255

最小可复现代码

kafka配置:

<?php

declare(strict_types=1);

use Hyperf\Kafka\Constants\KafkaStrategy;

return [
    'default'     => [
        'connect_timeout'               => -1,
        'send_timeout'                  => -1,
        'recv_timeout'                  => -1,
        'client_id'                     => '',
        'max_write_attempts'            => 3,
        'bootstrap_servers'             => explode(',', env('KAFKA_LOG_BOOTSTRAP_SERVERS', '')),
        'acks'                          => -1,
        'producer_id'                   => -1,
        'producer_epoch'                => -1,
        'partition_leader_epoch'        => -1,
        'interval'                      => 0,
        'session_timeout'               => 60,
        'rebalance_timeout'             => 60,
        'replica_id'                    => -1,
        'rack_id'                       => '',
        'group_retry'                   => 5,
        'group_retry_sleep'             => 1,
        'group_heartbeat'               => 3,
        'offset_retry'                  => 5,
        'auto_create_topic'             => true,
        'partition_assignment_strategy' => KafkaStrategy::RANGE_ASSIGNOR,
        'pool'                          => [
            'min_connections' => 1,
            'max_connections' => 10,
            'connect_timeout' => 10.0,
            'wait_timeout'    => 3.0,
            'heartbeat'       => -1,
            'max_idle_time'   => 60.0,
        ],
    ],
    'log_service' => [
        'app'       => env('KAFKA_LOG_APP', ''),
        'topic'     => env('KAFKA_LOG_TOPIC', '--topic--’),
        'bootstrap' => env('KAFKA_LOG_BOOTSTRAP_SERVERS', '--bootstrap--‘),
    ],
];

<?php
declare(strict_types=1);

namespace App\Service\QueueService;

use App\Service\PageService\BasePS;
use Hyperf\Contract\ConfigInterface;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Kafka\Producer;
use Hyperf\Logger\LoggerFactory;
use Hyperf\Contract\ContainerInterface;

class KafkaQS
{

    protected $producer;
    protected $logger;
    protected $config;
    protected $container;
    protected $request;

    public function __construct(ContainerInterface $container, Producer $producer, RequestInterface $request)
    {
        $this->producer  = $producer;
        $this->container = $container;
        $this->config    = $container->get(ConfigInterface::class)->get('kafka.log_service');
    }

    /**
     * elkLog
     *
     * @param array $param
     * @return bool
     */
    public function elkLog(array $param = []): bool
    {
        $topic       = $this->config['topic'];
        $url         = $this->config['bootstrap'];

        $logStr = 'test demo';
        $this->producer->send($topic, $logStr, $url);
        return true;
    }

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.