PHP Memcached always returns 0

I have memcache(installed on php5) and memcached(installed on php7.2 via libmemcached) that connect to the same memcached daemon/server.

Memcache::getworks fine and receives data in line with my expectation. But when I do Memcached::get, it always returns 0.

I checked that I have compression when using both extensions. I also tried to switch between Memcached::OPT_BINARY_PROTOCOLfor memcachedand it still produces the same zero result.

Interestingly, when I add a key / value pair using the extension memcachedand retrieve using the same key, I get the correct / correct value that I added.

Now I do not know what might be the reason that it does not work for data already stored on the memcached server.

EDIT 1 . I made telnet for my memcached server and verified that this value is actually. In addition, I checked the result code returned Memcached::getResultCodeis not a failure.

EDIT 2 : I may have narrowed it down further. I noticed that when I save ["key1" => "value1"]from a memcache-php5script, it saves and retrieves the data correctly. But when I try to get the same data using a memcached-php7.1script, it returns 0.

"key1" memcached telnet. ["key1" => "value1"], memcached-php7.1 script, . memcache-php5 script "a:1:{s:4:\"key1\";s:6:\"value1\";}" ( json_encoded)

, , / memcached memcached.

P.S.: php. , .

+6
1

, memcache memcached - . , - memcache - -.

, , .

<?php
$memcache = new Memcache;
$memcacheD = new Memcached;
$memcache->addServer($host);
$memcacheD->addServers($servers);

$checks = array(
    123,
    4542.32,
    'a string',
    true,
    array(123, 'string'),
    (object)array('key1' => 'value1'),
);
foreach ($checks as $i => $value) {
    print "Checking WRITE with Memcache\n";
    $key = 'cachetest' . $i;
    $memcache->set($key, $value);
    usleep(100);
    $val = $memcache->get($key);
    $valD = $memcacheD->get($key);
    if ($val !== $valD) {
        print "Not compatible!";
        var_dump(compact('val', 'valD'));
    }

    print "Checking WRITE with MemcacheD\n";
    $key = 'cachetest' . $i;
    $memcacheD->set($key, $value);
    usleep(100);
    $val = $memcache->get($key);
    $valD = $memcacheD->get($key);
    if ($val !== $valD) {
        print "Not compatible!";
        var_dump(compact('val', 'valD'));
    }
}
+4

All Articles