ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
数据库配置文件位于 System 应用下的 Config 文件夹 /app/System/Config/Session.php ~~~ <?php namespace App\System\Config; class Session { public $name = 'SSID'; // 用在 cookie 或者 URL 中的会话名称, 例如:PHPSESSID。 只能使用字母和数字,建议尽可能的短一些 public $expire = 1440; // 超时时间 public $driver = 'Default'; // SESSION 驱动 Default:系统默认/Mysql/Memcache/Memcached/Redis // mysql 配置项 /* public $mysql = array( 'host' => '127.0.0.1', // 主机名 'port' => '3306', // 端口号 'user' => 'root', // 用户名 'pass' => '', // 密码 'name' => 'beV2', // 数据库名 'table' => 'session' // 存放session的表名 ); */ // memcache 配置项,二维数组,可存放多个服务器配置 /* public $memcache = array( array( 'host' => '127.0.0.1', // 主机名 'port' => '11211', // 端口号 'timeout' => 0, // 超时时间 'persistent' => false, // 是否使用长连接 'weight' => 1 // 权重 ) ); */ // memcached 配置项,二维数组,可存放多个服务器配置 /* public $memcached = array( array( 'host' => '127.0.0.1', // 主机名 'port' => '11211', // 端口号 'weight' => 1 // 权重 ) ); */ // REDIS 设置项,未设置时使用系统 REDIS 设置 /* public $redis = array( 'host' => '127.0.0.1', // 主机名 'port' => 6379, // 端口号 'timeout' => 0, // 超时时间 'persistent' => false, // 是否使用长连接 'password' => '', // 密码,不需要时留空 'db'=> 0 // 默认选中数据库 ); */ } ~~~ ## driver 驱动,配置缓存驱动类型,默认为PHP原生实现 当驱动类型为 Mysql/Memcache/Memcached/Redis 时,需要取消对应配置项注释,并配置相关参数 ## 使用 Mysql 存储 Session 需要在数据库中创建session表,表结构如下: ~~~ CREATE TABLE IF NOT EXISTS `session` ( `session_id` varchar(60) NOT NULL COMMENT 'session id', `session_data` varchar(21782) NOT NULL COMMENT 'session 数据', `expire` int(10) unsigned NOT NULL COMMENT '超时时间', PRIMARY KEY (`sessionId`), KEY `expire` (`expire`) ) ENGINE=MEMORY DEFAULT CHARSET=utf8; ~~~ 其中数据库引警使用了 ENGINE=MEMORY,该引擎不支持 Text 类型,因此能存放的数据有限,如果对存储内容长度有要求,可以改为其它存储引擎,如:InnoDB