简体   繁体   中英

How do you use memcached (not memcache) with PHP (part 2)

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM