/usr/local/bin/memcached -d -m 20 -u zhangy -p 13000 -P ./mem.pid
2、修改php的配置
vi /usr/local/php/lib/php.ini
session.save_handler = "memcache"
memcache.hash_strategy = "consistent"
session.save_path = "tcp://127.0.0.1:13000?weight=10,tcp://127.0.0.1:12000"
说明:第一行,session的储存方式是memcache;第二行,memcache的hash算法是consistent;第三行,session储存的地位;
3、重启apache
查看phpinfo
session
Session Support | enabled |
Registered save handlers | files user sqlite memcache |
Registered serializer handlers | php php_binary |
紧接着下面是:
session.save_path | tcp://127.0.0.1:13000,tcp://127.0.0.1:12000 | tcp://127.0.0.1:13000,tcp://127.0.0.1:12000 |
4、做个简单测试如下:
a)、准备文件session.php
<?php session_start(); $_SESSION['username'] = "abcabc"; echo session_id(); ?>
b)、显示session内容文件
<?php $mem = new Memcache; $mem->addServer("127.0.0.1",12000)or die ("Could not add server 12000"); $mem->addServer("127.0.0.1",13000)or die ("Could not add server 13000"); $val = $mem->get('qp0mrob2ovcqle3u4lbr4obsa5'); //echo session_id(); 得到的session id echo $val; ?>