V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
salamanderMH
V2EX  ›  问与答

docker 中编译 PHP 的 event 扩展出错

  •  
  •   salamanderMH · 2019-04-29 18:50:32 +08:00 · 984 次点击
    这是一个创建于 2053 天前的主题,其中的信息可能已经有所发展或是发生改变。

    问题

    这是我编译好的镜像 salamandermh/php-cli:7.1 然后查看docker run -it salamandermh/php-cli:7.1 bash发现

    php -m
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20160303/event.so' - Error relocating /usr/local/lib/php/extensions/no-debug-non-zts-20160303/event.so: php_sockets_le_socket: symbol not found in Unknown on line 0
    [PHP Modules]
    bcmath
    bz2
    Core
    ctype
    curl
    date
    dom
    fileinfo
    filter
    ftp
    gd
    hash
    iconv
    imagick
    json
    libxml
    mbstring
    mongodb
    mysqli
    mysqlnd
    openssl
    pcntl
    pcre
    PDO
    pdo_mysql
    pdo_sqlite
    Phar
    posix
    readline
    redis
    Reflection
    session
    SimpleXML
    sockets
    SPL
    sqlite3
    standard
    swoole
    tokenizer
    xml
    xmlreader
    xmlwriter
    xsl
    Zend OPcache
    zip
    zlib
    
    [Zend Modules]
    Zend OPcache
    
    

    php_sockets_le_socket: symbol not found in Unknown on line 0, 看样子是 sockets 扩展没找到,但是sockets扩展已经加载了,不知道是哪里没配置对

    Dockerfile在这里

    1 条回复    2019-07-10 11:26:46 +08:00
    salamanderMH
        1
    salamanderMH  
    OP
       2019-07-10 11:26:46 +08:00
    解决了,是扩展加载顺序问题

    because event was being loaded before sockets from the .ini's in /usr/local/etc/php/conf.d

    Going into your image, the ordering of these files determines which are loaded first
    ```
    /usr/local/etc/php/conf.d # ls -al
    total 28
    drwxr-xr-x 2 root root 4096 Jul 9 20:39 .
    drwxr-xr-x 7 root root 4096 Jul 9 20:01 ..
    -rw-r--r-- 1 root root 19 Jul 9 18:39 docker-php-ext-event.ini
    -rw-r--r-- 1 root root 82 Jul 9 18:39 docker-php-ext-opcache.ini
    -rw-r--r-- 1 root root 23 Jul 9 18:38 docker-php-ext-pdo_mysql.ini
    -rw-r--r-- 1 root root 21 Jul 9 18:38 docker-php-ext-sockets.ini
    -rw-r--r-- 1 root root 20 Jun 28 02:48 docker-php-ext-sodium.ini
    ```
    `docker-php-ext-enable` allows for a flag to change the `.ini` name, so doing a `docker-php-ext-enable --ini-name zz-event.ini event` has it load in last.

    正确的 Dockerfile
    ```
    FROM php:7.1.30-cli-alpine3.9

    # Packages
    RUN apk add --no-cache \
    autoconf \
    build-base \
    linux-headers \
    libevent-dev \
    openldap-dev \
    imagemagick-dev

    RUN docker-php-ext-install sockets pdo_mysql opcache

    RUN docker-php-ext-enable opcache && \
    pecl install event-2.5.3 && \
    docker-php-ext-enable --ini-name zz-event.ini event


    ENV COMPOSER_ALLOW_SUPERUSER 1
    ENV COMPOSER_HOME /tmp
    ENV COMPOSER_VERSION 1.5.1


    RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer \
    && composer --ansi --version --no-interaction

    VOLUME /var/www
    WORKDIR /var/www

    CMD [ "php", "./public/server.php" ]
    ```





    [github issue]( https://github.com/docker-library/php/issues/857)
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5036 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 07:57 · PVG 15:57 · LAX 23:57 · JFK 02:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.