请问session存在哪里会比较好?
请问各位大神,session是存哪里比较好?
回复内容:
请问各位大神,session是存哪里比较好?
建议在Cookie里放一个SessionID,然后在服务端存信息。
服务端放Redis就可以,而且这些数据对读性能要求较高,但稳定性要求不高
一台机器上搞,随便你怎么放
一个项目多台机器搞,就要用到可以多台web访问的方式,最简单的就是共享存储NFS也可以,Redis也可以,访问量不大的话MySQL也可以
多个项目多台机器相互隔离的需要同步登录的搞,那就稍微复杂点,需要实现SSO了,也不复杂
其实主要看应用场景,过度设计没有必要
我们也是放在redis里,还可以多台主机共享session,配置方法如下:
(1)目前是nginx+fastcgi+php5-fpm解析php
(2)修改/etc/php5/fpm/php.ini
session.save_path = "tcp://your_ip:your_port?auth=yourpasswd"
看phpredis中已经有说明了, phpredis的网站:https://github.com/nicolasff/phpredis...
参考:https://github.com/nicolasff/phpredis...
说明:
PHP Session handler
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.
看你的服务器架构以及系统需求。
如果只有一台服务器,你放哪儿都可以;如果前端有多台web server,那么需要一个专门存放session的服务器,具体使用什么,可以选择很多,比如redis、memcache、mysql或者其他。
用memcache也是一个好办法,最主要是支持分布式哦亲~~~~一台或者多台服务器都可以

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

PHP 8.4 带来了多项新功能、安全性改进和性能改进,同时弃用和删除了大量功能。 本指南介绍了如何在 Ubuntu、Debian 或其衍生版本上安装 PHP 8.4 或升级到 PHP 8.4

CakePHP 是 PHP 的开源框架。它的目的是使应用程序的开发、部署和维护变得更加容易。 CakePHP 基于类似 MVC 的架构,功能强大且易于掌握。模型、视图和控制器 gu

Visual Studio Code,也称为 VS Code,是一个免费的源代码编辑器 - 或集成开发环境 (IDE) - 可用于所有主要操作系统。 VS Code 拥有针对多种编程语言的大量扩展,可以轻松编写
