Home > Backend Development > PHP Tutorial > php使用memcache存储session 服务器配置方法

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

WBOY
Release: 2016-06-20 12:59:47
Original
888 people have browsed it

Memcached-1.4.4-14 For Win32 or Win64


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

session.save_handler = files
Copy after login

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

# windows平台session.save_path = "N:/path"# linux平台session.save_path = "/path"
Copy after login


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


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

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

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

php_value session.save_handler = memcachephp_value session.save_path = tcp://127.0.0.1:11211
Copy after login

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

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

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


使用多个 memcached server 时用英文逗号","隔开,并且和 Memcache::addServer() 文档中说明的一样,可以带额外的参数"persistent"、"weight"、"timeout"、"retry_interval" 等等,类似这样的:

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


以上文档参考:

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template