We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon 2.0 Libmemcached problem

Today I cloned and installed Phalcon 2.0. The installation wen smoothly but my unit tests start failing. The problem simes to be the Libmemcached backend or Json frontend. On Phalcon 1.3 everything is fine.

This is how I set my backend:

$frontCache = new Json(['lifetime' => 172801]);

$cache = new Libmemcached($frontCache, [
    'servers' => [
        [
            'host'       => $this->config->auth->host,
            'port'       => $this->config->auth->port,
            'persistent' => true,
        ]
    ],
    'client' => [
        Memcached::OPT_PREFIX_KEY => $this->config->auth->prefix,
    ]
]);

I can see values stored in memcache with the good key prefix but I cant get them back.

$this->backend->get($key);

Also on Phalcon 1.3 there was a method $cache->setTrackingKey() which seems missing in 2.0. I thought 2.0 is backwards compatibile with 1.3. Is it ?



98.9k

Phalcon 2 is backwards compatible with 1.3. Maybe the implementation still need some work.

Looks like it's not fully compatible yet (for example mentioned method $cache->setTrackingKey() is not evailable in 2.0

On 1.3 all the unit and functional tests I have pass - on 2.0 there are problems.

I to test this I created simple controller with two methods set (which I call first) and get:

use Memcached;
use Phalcon\Cache\Backend\Libmemcached;
use Phalcon\Cache\Frontend\Json;
use Phalcon\Mvc\Controller;

class TestController extends Controller
{

public function mcSetAction()
{
    $cache = $this->getBackend();
    $cache->save('myKey', 'some text'); // Sets the value properly in MC
}

public function mcGetAction()
{
    $cache = $this->getBackend();
    $phValue = $cache->get('myKey');
    var_dump($phValue); // Here I get NULL

    $mc = new Memcached();
    $mc->addServer('127.0.0.1', 11211);

    $rawValue = $mc->get('auth.myKey');
    $rawValue = json_decode($rawValue);
    var_dump($rawValue); // Here I get "some text"
}

private function getBackend()
{
    $frontCache = new Json(['lifetime' => 172801]);

    $cache = new Libmemcached($frontCache, [
        'servers' => [
            [
                'host'       => '127.0.0.1',
                'port'       => '11211',
                'persistent' => true,
            ]
        ],
        'client' => [
                Memcached::OPT_PREFIX_KEY => 'auth.',
        ]
    ]);

    return $cache;
}
}

Investigating some more I found this: https://github.com/phalcon/cphalcon/blob/2.0.0/phalcon/cache/backend/libmemcached.zep#L148

Why there is no return statment?



2.1k
Accepted
answer

Looks like this was the issue. Here is the pull request fixing it: https://github.com/phalcon/cphalcon/pull/2978