- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
如果我这样做:
ini_set('session.gc_maxlifetime', 86400);
这是否意味着用户可以将浏览器留在同一页面上(不活动)最多 1 天,而不必担心 session 被垃圾收集和他们被注销?
如果服务器配置不支持这个会发生什么? (它会给我一个错误吗?还是默默地失败?)
默认的垃圾收集时间是 24 分钟,这在我的系统中很容易发生。
垃圾收集是否在 session_start 上运行?
最佳答案
对于像您这样的问题,我倾向于直接查看每个 ini 设置的 PHP 手册页:http://php.net/session.gc_maxlifetime:
session.gc_maxlifetime
integersession.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
andsession.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?
这仅表示 session 未被垃圾回收。如果用户由于某些其他原因(例如 cookie 丢失或某些其他 session ID 携带参数)丢失了 session ID,则无论 session 是否已被垃圾收集,用户都将自己视为已注销。
- What happens if the server configuration doesn't support this? (Will it give me an error? or just fail silently?)
那是 PHP 配置而不是服务器配置。但是,如果您没有以默认方式使用默认 session 目录将文件放在那里,它不会给您任何错误并静默失败。负责 session 数据垃圾收集是服务器管理的职责。
如果是标准配置但没有足够的文件权限,则会触发错误。
在内部,也可以启用 session 调试,以便您可以获得有关删除了多少 session 文件的消息。
另请参阅此相关问答:
- The default garbage collection time is 24 minutes which could happen in my system easily.
是的,默认设置是“1440
”,代表 1440 秒,即 24 分钟。
您可以在此处的 PHP 源代码中找到它:
它也与 PHP 附带的建议 ini 设置使用的值相同。
另请参阅此相关问答:
- Does garbage collection run on session_start?
是的。您可以在 session_start
实现的末尾找到它:
那么随着所有这些信息的泛滥,我们应该吸取哪些教训呢? PHP 对 session 数据进行垃圾回收,因为如果启用了 session ,将很容易产生大量数据。使用 session 保存目录的标准设置,它可以很快填满大量文件。我自己经历过这种情况,因为我在没有启动标准垃圾收集的应用程序中存在一些缺陷(我更改了 session 保存路径,因为该站点位于共享主机上并且我自己的垃圾收集没有被正确触发/配置),所以最后我所能做的就是从 shell 访问该目录并让 find
完成真正需要很长时间的工作 - 但它有效。所以手动垃圾收集。
因此,请检查您的垃圾收集设置,并在一两天后验证这些设置是否按预期工作。
除了纯垃圾回收之外,在您的应用程序中独立跟踪 session 生命周期也是明智的。这是通过将 session 创建时间和 session 上次事件时间添加到 session 中来实现的。如果您想允许长时间运行的 session 甚至强制用户在特定时间跨度后重新登录,这将允许您重新生成 session ID。
此外,对于 session 尚未被垃圾收集器删除的情况,这也可以保护您的 session 处理,因为可能没有捕获到它,或者因为它是唯一可用的 session 。由于垃圾收集器在 session 启动后启动的设计问题,垃圾收集器永远不会删除当前 session 。
我希望这能回答您的问题并为您提供一些指导。
关于php - ini_set 'session.gc_maxlifetime' 为 1 天,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24337474/
是否为每个 Shiny session 分配了 session ID/ session key (如果部署在 Shiny 服务器上)?如果是,我如何访问该信息?我已阅读文档here然而上网查了一下,并
我正在使用 this koajs session 模块。 我检查了源代码,但我真的无法理解。 我想知道它保存 session 数据的位置,因为我没有看到创建的文件,并且当服务器重新启动时, sessi
实现高可扩展性的一种方法是使用网络负载平衡在多个服务器之间分配处理负载。 这种方法提出的一个挑战是服务器是否具有状态意识 - 将用户状态存储在“ session ”中。 此问题的一个解决方案是“粘性
在负载平衡服务器的上下文中, session 亲和性和粘性 session 之间有什么区别? 最佳答案 我见过这些术语可以互换使用,但有不同的实现方式: 在第一个响应中发送 cookie,然后在后续响
我希望其他人向我解释哪种方法更好:使用 session 或设计无 session 。我们正在开始开发一个新的 Web 应用程序,但尚未决定要遵循什么路径。 无 session 设计在我看来更可取: 优
现在用户在他的权限中有很多角色,我将允许他点击 href 并在新窗口中扮演另一个角色。每个角色都有自己的 session 。 既然浏览器打开窗口不能用新 session 打开,我必须在服务器端想办法。
我正在尝试为express.js Node 应用程序实现 session 存储我的问题是: 如何删除具有浏览器 session 生命周期的 cookie(根据连接文档标记有 expires = fal
在开始在 golang 中使用 session 之前,我需要回答一些问题 session 示例 import "github.com/gorilla/sessions" var store = ses
我读过 Namespaced Attributes . 我尝试使用此功能: #src/Controller/CartController.php public function addProduct(
我正在努力完成以下工作: 根据用户的类型更改用户的 session cookie 到期日期。 我有一个 CakePHP Web 应用程序,其中我使用 CakePHP session 创建了我的身份验证
这是我在这里的第一个问题,我希望我做对了。 我需要处理一个 Java EE 项目,所以在开始之前,我会尝试做一些简单的事情,看看我是否能做到。 我坚持使用有状态 session Bean。 这是问题:
ColdFusion session 与 J2EE session 相比有什么优势吗? ColdFusion session documentation提到了 J2EE session 的优点,但没有
在执行任何任务之前,我需要准确地在创建 session 时创建一个 session 范围变量(因为我的所有任务都需要一个初始 session 范围变量才能运行)。因为,创建 session 时,gra
我们当前的应用使用 HTTP session ,我们希望将其替换为 JWT。 该设置仅允许每个用户进行一次 session 。这意味着: 用户在设备 1 上登录 用户已在设备 1 上登录(已创建新 s
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
假设我在两个或更多设备上打开了两个或更多用户 session (同一用户没有管理员权限)。 在当前 session 中,如果我注销,是否意味着所有其他 session 也会关闭?如果没有,有没有办法通
我正在评估在 tomcat 中使用带有 session 复制的粘性 session 的情况。根据我的初步评估,我认为如果我们启用 session 复制,那么在一个 tomcat 节点中启动的 sess
我开始使用 golang 和 Angular2 构建一个常规的网络应用程序,最重要的是我试图在 auth0.com 的帮助下保护我的登录.我从 here 下载快速入门代码并尝试运行代码,它运行了一段时
我在 Spring Controller 中有一个方法,它接受两个相同类型的参数其中一个来自 session ,另一个来自表单提交(UI)。 问题是在 Controller 方法中我的非 sessio
在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。 登录后,我可以继续我的业务,并访问我的安全约束内外的资源。
我是一名优秀的程序员,十分优秀!