php使用memcache存储session 服务器配置方法

Memcached-1.4.4-14 For Win32 or Win64
http://my.oschina.net/u/205403/blog/390256
php


查看 php.ini 可见 session 的默认存储方式是 files,以下linux

session.save_handler = files

session 的默认存储路径为
对于windows为:C:/Windows/Temp
对于linux为:未知
shell

# windows平台
session.save_path = "N:/path"

# linux平台
session.save_path = "/path"


咱们知道是用 files 文件系统来存储的话,每次 session 时都会生成一个文件,效率很低下,若是服务器上安装了 memcache ,那么务必要迁移到 memcache 来存储 session,作法以下:windows


方法一(服务器上修改):php.ini 中全局设置
服务器

session.save_handler = memcache  
session.save_path = "tcp://127.0.0.1:11211"

方法二(FTP上修改): 在网站跟目录下的 .htaccess
session

php_value session.save_handler = memcache
php_value session.save_path = tcp://127.0.0.1:11211

备注:后面的值加不加英文双引号都行tcp

方法三(程序上修改): 某一个应用程序中
memcached

ini_set("session.save_handler", "memcache");  
ini_set("session.save_path", "tcp://127.0.0.1:11211");


使用多个 memcached server 时用英文逗号","隔开,而且和 Memcache::addServer() 文档中说明的同样,能够带额外的参数"persistent"、"weight"、"timeout"、"retry_interval" 等等,相似这样的:
网站

php_value session.save_path = tcp://host1:port1?persistent=1&weight=2,tcp://host2:port2


以上文档参考:http://koda.iteye.com/blog/466667
spa

相关文章
相关标签/搜索