php - 大约 25 分钟后 session 丢失

标签 php apache session configuration

我在 apache 服务器 2.4.16 上使用 PHP 5.5.38。一段时间后(大约 25 分钟),我遇到了失去 session 的问题。我在 php.ini 文件中找到了这些参数

session.gc_maxlifetime = 1440
session.gc_probability = 10

但是在代码中这些已经被设置为不同的值。代码看起来像这样

ini_set('session.gc_maxlifetime', 60*60*24*7);
ini_set('session.use_cookies', 1);
ini_set('session.gc_probability', 0);

我确认他们返回旧值,这意味着它没有失败或其他什么。

我不知道还有什么地方可以找到丢失 session 的原因。任何想法或建议将不胜感激。

最佳答案

当您使用 ini_set() 设置配置值时,它仅在当前脚本执行期间持续存在:

The configuration option will keep this new value during the script's execution, and will be restored at the script's ending.

并且,当 session.gc_maxlifetime 有多个值时,垃圾收集器将使用最低的值:

If different scripts have different values of session.gc_maxlifetime but share the same place for storing the session data then the script with the minimum value will be cleaning the data.

所以您需要做的是在您使用 session 的每个页面中分配ini_set(),或者,更好的选择是直接修改php.ini 文件到你需要的值。

请注意,25 分钟大约是 1440 秒(24 分钟),因此它肯定使用 php.ini 的值。

关于php - 大约 25 分钟后 session 丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46198761/

相关文章:

php - MySQL通过相同的id输出不同的值

javascript - 如何从无限循环的 Javascript 函数向 MySQL 传递值?

JAVA Apache HttpClient SSL 超时

oracle - 当 session 在没​​有连接的情况下打开和关闭时,Hibernate 查询停止

session - 使用findAll时,Grails不会保存,但是使用collection时,Grails会保存

javascript - PHP 函数仅在未直接访问时运行

php - 错误 : Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY'

regex - 将所有流量重定向到另一个域的根

apache - 在 Dreamweaver CS4 中配置 Subversion 版本控制

javascript - Ajax 请求和 SESSION