博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP session用redis存储
阅读量:5309 次
发布时间:2019-06-14

本文共 2240 字,大约阅读时间需要 7 分钟。

redis的官方github这么说:

 

phpredis can be used to store PHP sessions. To do this, configure session.save_handler and session.save_path in your php.ini to tell phpredis where to store the sessions:

来自:

 

确实是个不错方法

 

phpredis can be used to store PHP sessions. To do this, configure session.save_handler and session.save_path in your php.ini to tell phpredis where to store the sessions:
session.save_handler = redis
session.save_path = "tcp://host1:6379?weight=1, tcp://host2:6379?weight=2&timeout=2.5, tcp://host3:6379?weight=2"
session.save_path can have a simple host:port format too, but you need to provide the tcp:// scheme if you want to use the parameters. The following parameters are available:
weight (integer): the weight of a host is used in comparison with the others in order to customize the session distribution on several hosts. If host A has twice the weight of host B, it will get twice the amount of sessions. In the example, host1 stores 20% of all the sessions (1/(1+2+2)) while host2 and host3 each store 40% (2/1+2+2). The target host is determined once and for all at the start of the session, and doesn't change. The default weight is 1.
timeout (float): the connection timeout to a redis host, expressed in seconds. If the host is unreachable in that amount of time, the session storage will be unavailable for the client. The default timeout is very high (86400 seconds).
persistent (integer, should be 1 or 0): defines if a persistent connection should be used. (experimental setting)
prefix (string, defaults to "PHPREDIS_SESSION:"): used as a prefix to the Redis key in which the session is stored. The key is composed of the prefix followed by the session ID.
auth (string, empty by default): used to authenticate with the server prior to sending commands.
database (integer): selects a different database.
Sessions have a lifetime expressed in seconds and stored in the INI variable "session.gc_maxlifetime". You can change it with ini_set(). The session handler requires a version of Redis with the SETEX command (at least 2.0). phpredis can also connect to a unix domain socket: session.save_path = "unix:///var/run/redis/redis.sock?persistent=1&weight=1&database=0.

转载于:https://www.cnblogs.com/jking10/p/5710482.html

你可能感兴趣的文章
爬虫开发13.UA池和代理池在scrapy中的应用
查看>>
[Javascript] Classify JSON text data with machine learning in Natural
查看>>
用户十秒离开你网站的15大原因
查看>>
通信之中的原理--噪声做加密
查看>>
java多线程编程题之连续打印abc的几种解法
查看>>
SUSE Linux Enterprise 11 安装 MySQL笔记
查看>>
Java程序性能优化
查看>>
zoj 1842 Prime Distance
查看>>
Linux 文件属性
查看>>
Oracle基础学习笔记(一)
查看>>
iOS 开发笔记-plist使用
查看>>
BZOJ4013 : [HNOI2015]实验比较
查看>>
界面控件DevExpress发布v18.2.5|附下载
查看>>
【重大更新】DevExpress WinForms v18.2新版亮点(七)
查看>>
Jquery实现让滚动条始终保持在最下方
查看>>
java中三种常见内存溢出错误的处理方法
查看>>
从CPU/OS到虚拟机和云计算
查看>>
Luogu 3960 [NOIP2017] 列队 - splay|线段树
查看>>
输出100以内的质数
查看>>
成长——新的开始,一切都是美好的
查看>>