phpfastcache无法加载Memcache的驱动程序

时间:2017-04-18 19:22:52

标签: php memcached phpfastcache

我正在尝试为我的php项目实现memcached,我的代码永远不会通过CacheManager :: getInstance()调用,因为phpFastCache正在轰炸实例化缓存的正确驱动程序。它失败的确切线是:

return class_exists('Memcached');

是Memcached / Driver.php文件的第65行。

无论我做什么,

都会返回false。我也尝试过使用memcache,但它也在类上存在炸弹线。提前谢谢。

这是我的测试代码

<?php

require 'vendor/autoload.php';
use phpFastCache\CacheManager;

class MemcacheTest extends PHPUnit_Framework_TestCase
{
    var $adapter;

    function setUp()
    {

    }

    function tearDown()
    {

    }

    function testMemecached()
    {
        $InstanceCache = CacheManager::getInstance('memcached',['servers' => [
            [
                'host' => 'memcached_container',
                'port' => 11211,
                // 'sasl_user' => false, // optional
                // 'sasl_password' => false // optional
            ],
        ]]);

        $key = "sumkey";
        $CachedString = $InstanceCache->getItem($key);
        $result = $CachedString->get();
        if (is_null($result)) {
            $CachedString->set("here we are")->expiresAfter(120);
            $result = $InstanceCache->save($CachedString);
        } else {
            $skin = $CachedString->get();
        }
    }
}

php 7 phpfastcache 6.1

1 个答案:

答案 0 :(得分:0)

我认为您应该在容器中同时安装 memcached 和 memcache,这是我的 docker 文件中的 memcache/memcached 部分:

FROM php:$7.0-fpm-stretch
RUN apt-get update && apt-get install -y \
        libmemcached11 \
        libmemcachedutil2 \
        libmemcached-dev \
        libz-dev \
        git \
        zip \
    && cd /root \
    && git clone -b php7 https://github.com/php-memcached-dev/php-memcached \
    && cd php-memcached \
    && phpize \
    && ./configure \
    && make \
    && make install \
    && cd .. \
    && rm -rf  php-memcached \
    && echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
    && apt-get remove -y build-essential libmemcached-dev libz-dev \
    && apt-get remove -y libmemcached-dev libz-dev \
    && apt-get autoremove -y \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean  ; \
  yes | pecl install memcache-4.0.5.2; \
  echo extension=memcache.so >> /usr/local/etc/php/conf.d/memcache.ini;