0

On the first page, I have this

// start memcached
$m = new Memcached();
$m->addServer('localhost', 11211);
$key = 'test_' . $ID_ref;
$test_data = array(....);
$m->set($key, $test_data);
// end memcached

OK, so far. On the next page,

// start memcached
$m = new Memcached();
$m->connect('localhost', 11211);
var_dump($m->get($key));
// end memcached

The following error occured:

Call to undefined method Memcached::connect()

phpinfo() shows that memcached is installed by webhost, and it seems that memcached does not support connect()

What should I use instead?

1 Answer 1

3

Rather than

$m = new Memcached();
$m->connect('localhost', 11211);

simply re-use

$m = new Memcached();
$m->addServer('localhost', 11211);

connect() is a Memcache method and not Memcached

Sign up to request clarification or add additional context in comments.

5 Comments

I got this output bool(false) What does it mean?
Just ensure your $key values are the same on both set() and get() calls. If you wish to test it's working OK you can perform a set and a get after each other in the same script.
they are the same, I've set both to $key = 'test_1'; for both with the same result
It is bool(false) also on the same script.
I'm not sure what else to help you with sorry, memcached really is a simple little beastie, you can try getting a memcache admin panel to check that you're successfully storing keys. eg code.google.com/p/phpmemcacheadmin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.