Memcached 实现session共享


本实例是在lamp/lnmp环境下实现

1.编辑php.ini添加两行    #两种架构通用型,但有可能不能运行

session.save_handler = memcache 

        session.save_path = tcp://192.168.0.9:11211  #远程数据库服务器IP

2.或者httpd.conf中对应的虚拟主机中添加    #lamp架构配置

php_value session.save_handler "memcache" 

        php_value session.save_path "tcp://192.168.0.9:11211"  

3.或者php-fpm.conf对应的pool中添加        #lnmp架构配置

php_value[session.save_handler] = memcache

php_value[session.save_path] = " tcp://192.168.0.9:11211 "


注意:有时=后面的配置,加双引号会出问题,注意排查

Memcached session测试


wget http://study.lishiming.net/.mem_se.txt

mv .mem_se.txt  /usr/local/apache2/htdocs/session.php  #网站根目录下,用httpd环境测试

curl localhost/session.php 或者curl -x127.0.0.1:80 htdocs/session.php

类似于1443702394

1443702394

i44nunao0g3o7vf2su0hnc5440

telnet 127.0.0.1 11211

get i44nunao0g3o7vf2su0hnc5440  #查看数据是否为1443702394