drm16022 2014-09-30 14:18
浏览 48
已采纳

Docker容器中的Couchbase PHP SDK

I have a Docker container that runs PHP-FPM 5.5 and I'd like to ensure that it has access to the Couchbase SDK. I have this working outside of Docker and can't really picture how Docker would interfere and yet I seem to be running into a problem that is "probably" docker related:

My Docker container runs under Ubuntu 14.04 and includes the following installation (after installing PHP):

# Install Couchbase C-library and PECL extension
RUN wget -O/etc/apt/sources.list.d/couchbase.list http://packages.couchbase.com/ubuntu/couchbase-ubuntu1404.list \
        && wget -O- http://packages.couchbase.com/ubuntu/couchbase.key | sudo apt-key add - \
        && apt-get update \
        && apt-get install -y --no-install-recommends pkg-config libcouchbase2-libevent libcouchbase-dev libmemcached-dev php-pear php5-dev make \
        && pecl config-set php_ini /app/conf/php.ini \
        && pecl install couchbase --alldeps \
        && pecl install memcached --alldeps \
        && { \
            echo "; Couchbase PHP SDK"; \
            echo "extension=/usr/lib/php5/20121212/couchbase.so"; \
        } > /etc/php5/fpm/conf.d/30-couchbase.ini \
        && cp /etc/php5/fpm/conf.d/30-couchbase.ini /etc/php5/cli/conf.d \
        && { \
            echo "; Memcached PHP SDK"; \
            echo "extension=/usr/lib/php5/20121212/memcached.so"; \
        } > /etc/php5/fpm/conf.d/30-memcached.ini \
        && cp /etc/php5/fpm/conf.d/30-memcached.ini /etc/php5/cli/conf.d

This SHOULD install both the C-libraries and the PECL extensions for Couchbase and Memcached support. In many ways it DOES appear to:

  • php -m does include these modules as installed,
  • and phpinfo() reports on their configuration as such:

couchbase

memcached

However, whenever I try to instantiate either a Couchbase or Memcached class can't find the class. So if I run the following program:

<?php
    $foo = new Couchbase();
    $bar = new Memcached();
    print_r($foo);
    print_r($bar);
?>

it gives me the following error:

PHP Fatal error: Class 'Couchbase' not found in /app/test.php on line 2


UPDATE: It turns out, however, that while Couchbase does not work, Memcached does. Not sure if that helps or hurts the troubleshooting but Couchbase seems to be the exclusive pain point.

  • 写回答

1条回答 默认 最新

  • du7979 2014-09-30 21:19
    关注

    The answer, it appears, has to do with Couchbase moving from their 1.x to 2.x SDK's which in the case of PHP means that there is no longer a class called "Couchbase".

    The longer term answer will be to migrate to this new API; which does look like it will require some work. In the near term, however, I needed a solution that would work for my existing use of Couchbase and that is quite simple ... just install the right version of Couchbase:

     pecl install couchbase-1.2.2
    

    That's all that was needed for me. You can see a working Docker of this setup at: lifegadget/docker-php

    Note: the default version of the SDK you get from PECL is now 2.0 so if you're not specifying a version you're getting version 2.x.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 易语言把MYSQL数据库中的数据添加至组合框
  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况