radamnyc
radamnyc

Reputation: 157

phpfastcache cant load driver for Memcache

I'm trying to implement memcached for my php project and my code never gets past the CacheManager::getInstance() call because the phpFastCache is bombing on instantiating the right driver for the cache. the exact line it is failing on is:

return class_exists('Memcached');

which is line 65 of the Memcached/Driver.php file.

this returns false no matter what i do. i have also tried using memcache as well but it also bombs on the class exists line. thanks in advance.

here is my test code

<?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

Upvotes: 1

Views: 868

Answers (1)

MocXi
MocXi

Reputation: 466

I think you should install both memcached and memcache in your container, here is my memcache/memcached part in my docker file:

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;

Upvotes: 0

Related Questions