php – ini_set’session.gc_maxlifetime’为期1天

如果我做:

ini_set('session.gc_maxlifetime', 86400);

这是否意味着用户可以将浏览器放在同一页面上(非活动状态)长达1天,而无需担心会话被垃圾回收并且他们被注销了?

如果服务器配置不支持,会发生什么? (它会给我一个错误吗?或者只是地失败?)

认的垃圾收集时间是24分钟,这可能很容易在我的系统中发生.

垃圾收集是否在session_start上运行?

解决方法:

对于像你这样的问题,我倾向于指向每个ini设置中存在的PHP手册页:http://php.net/session.gc_maxlifetime

session.gc_maxlifetime integer

session.gc_maxlifetime specifies the number of seconds after which data will be seen as ‘garbage’ and potentially cleaned up. Garbage collection may occur during session start (depending on session.gc_probability and session.gc_divisor).

  • Note:
    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. In this case, use this directive together with session.save_path.

  • Note: If you are using the default file-based session handler, your filesystem must keep track of access times (atime). Windows FAT does not so you will have to come up with another way to handle garbage collecting your session if you are stuck with a FAT filesystem or any other filesystem where atime tracking is not available. Since PHP 4.2.3 it has used mtime (modified date) instead of atime. So, you won’t have problems with filesystems where atime tracking is not available.

要在您的各种问题上进行映射:

  • Does this mean the user can leave there browser on the same page (inactive) for up to 1 day without the worry of the session being garbage collected and them being logged out?

它只意味着会话不是垃圾回收.如果用户由于某些其他原因(例如,cookie丢失或其他会话ID携带参数)而丢失了会话ID,则无论会话是否已被垃圾收集,用户似乎都会被注销.

  • What happens if the server configuration doesn’t support this? (Will it give me an error? or just fail silently?)

那就是PHP配置而不是服务器配置.但是,如果您没有使用认会话目录以认方式将文件放在那里,它将不会给您任何错误并以静​​方式失败.服务器管理的业务是处理会话数据垃圾收集.

如果是标准配置但文件权限不足,则会触发错误.

在内部,也可以启用会话调试,以便您可以获取有关已删除的会话文件数的消息.

另见Q& A:

> cleanup php session files
> Session Files Not Getting Cleaned Up

  • The default garbage collection time is 24 minutes which Could happen in my system easily.

是,认设置为“1440”,代表1440秒,即24分钟.

您可以在PHP代码中找到它:

> http://lxr.php.net/xref/PHP_5_5/ext/session/session.c#789

它也与PHP附带的建议ini-settings使用的值相同.

另见Q& A:

> PHP : What is the default lifetime of a session

  • Does garbage collection run on session_start?

是的,它确实.您可以在session_start实现的末尾找到它:

> http://lxr.php.net/xref/PHP_5_5/ext/session/session.c#1465

所有这些信息溢出,哪些经验值得学习? PHP具有会话数据的垃圾收集,因为如果启用了会话,则很容易生成大量数据.使用会话保存目录的标准设置,它可以很快填满大量文件.我经历过这种情况,因为我在应用程序中遇到了一些缺陷,标准垃圾收集没有启动(我更改了会话保存路径,因为该站点位于共享的主机上并且我自己的垃圾收集没有被正确触发/配置),所以最后我所能做的就是从shell访问该目录,让我们找到真正花了很长时间的工作 – 但它确实有效.所以手动垃圾收集.

因此,请检查您的垃圾收集设置,并在一两天后验证这些设置是否按预期工作.

在纯垃圾收集旁边,在应用程序中独立跟踪会话生命周期也是理智的.这可以通过将会话创建时间和会话上次活动时间添加到会话中来实现.如果您想允许长时间运行的会话,甚至强制用户在一定的时间跨度后重新登录,这将允许您重新生成会话ID.

此外,这可以保护您的会话处理,以防止到目前为止垃圾收集器尚未删除会话的情况,因为概率没有捕获它,或者因为它是唯一可用的会话.对于垃圾收集器在会话启动后启动的设计问题,垃圾收集器永远不能删除当前会话.

我希望这能回答你的问题,并为你提供一些指导.

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...