前提: 1、配置各php支持使用memcache; 2、安装配置好memcached服务器,这里假设其地址为172.16.200.11,端口为11211; 一、配置php将会话保存至memcached中 编辑php.ini文件,确保如下两个参数的值分别如下所示: session.save_handler = memcache session.save_path = "tcp://172.16.200.11:11211?persistent=1&weight=1&timeout=1&retry_interval=15" 二、测试 新建php页面setsess.php,为客户端设置启用session:
"; print "Session ID: " . session_id(); ?> 新建php页面showsess.php,获取当前用户的会话ID: connect('172.16.200.11', 11211); $mysess=session_id(); var_dump($memcache_obj->get($mysess)); $memcache_obj->close(); ?> Session Test
16 Current session id: