Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why php-memcached incompatible with memcached itself #426

Open
PutinVladimir opened this issue Jan 10, 2019 · 0 comments
Open

Why php-memcached incompatible with memcached itself #426

PutinVladimir opened this issue Jan 10, 2019 · 0 comments

Comments

@PutinVladimir
Copy link

PutinVladimir commented Jan 10, 2019

<?php
// Use direct access to memcached
$memcached = fsockopen ("unix:///var/run/memcached/memcached.sock",-1);

if (!$memcached) {
    echo "$errstr ($errno)\n";
}

$key = 'key';
$flags = 1;
$expire = 1000;
$data = "test";
$length = strlen($data);

if (!fwrite($memcached, "set {$key} {$flags} {$expire} {$length}\r\n{$data}\r\n")) {
        throw new Exception('Memcached write error.');
}

// Now try get key thru php-memcached
$phpmemcached = new Memcached();
$phpmemcached->setOptions([
    \Memcached::OPT_COMPRESSION => false,
    \Memcached::OPT_BINARY_PROTOCOL => true
]);

$phpmemcached->setOption(Memcached::OPT_USER_FLAGS, 1);

$phpmemcached->addServer('/var/run/memcached/memcached.sock', 0);

$value = $phpmemcached->get($key, null, Memcached::GET_EXTENDED);

var_dump($value);

/*
/array(3) {
  'value' =>
  int(0)
  'cas' =>
  int(35)
  'flags' =>
  int(0)

Where is my data???
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant