PHP连接MemcacheD测试代码

安装好了memcacheD,如何通过php来连接之,测试是否正确运行呢?下面这段代码可以帮助我们测试。注意,我们使用的是memcacheD.

$cacheServer = new Memcached(); //create memcacheD instance $cacheServer->addServer('127.0.0.1', 11211); //connect to memcacheD server$cacheServer->set('uname', 'flower'); // add key and value$value = $cacheServer->get('uname'); //get value through keyecho $value . "\n";

如果想把session存储到memcacheD中该如何做呢?注意:这里没有“tcp://”

session.save_handler = memcachedsession.save_path = "127.0.0.1:11211"

当然,也可以通过php文件来单独定义

ini_set("session.save_handler","memcached"); ini_set("session.save_path","127.0.0.1:11211");
Scroll to Top