php 检索php服务器会话超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14796492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 07:58:59  来源:igfitidea点击:

retrieve php server session timeout

phpsession

提问by NVG

I want to retrieve the value of session.gc_maxlifetimefrom the PHP server settings ( the time after which the session expires after no activity ). Very important : I do not want to change it, I only wish to retrieve its value ( maybe the value is different from server to server ) and I want to use a PHP script that I made to warn users properly, depending on the settings of those server.

我想session.gc_maxlifetime从 PHP 服务器设置中检索 的值(没有活动后会话过期的时间)。非常重要:我不想更改它,我只想检索它的值(可能值因服务器而异)并且我想使用我制作的 PHP 脚本来正确警告用户,具体取决于设置那些服务器。

Thank you.

谢谢你。

回答by n-dru

That's where ini_getfunction comes in hand:

这就是ini_get函数派上用场的地方:

$maxlifetime = ini_get("session.gc_maxlifetime");

From manual we read:

从手册中我们读到:

session.gc_maxlifetimeintegersession.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).

session.gc_maxlifetime整数session.gc_maxlifetime 指定数据将被视为“垃圾”并可能被清理的秒数。会话启动期间可能会发生垃圾收集(取决于 session.gc_probability 和 session.gc_divisor)。

回答by Kris Roofe

session.gc_maxlifetimeis not the time after which the session expires after no activity. gc here may be mean garbage collenction. As the php manualsays,

session.gc_maxlifetime不是会话在没有活动后到期的时间。gc 这里可能意味着垃圾收集。正如php手册所说,

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.

session.gc_maxlifetime 指定数据将被视为“垃圾”并可能被清理的秒数。会话启动期间可能会发生垃圾收集(取决于 session.gc_probability 和 session.gc_divisor)。

注意:如果不同的脚本具有不同的 session.gc_maxlifetime 值,但共享相同的存储会话数据的位置,那么具有最小值的脚本将清理数据。在这种情况下,将此指令与 session.save_path 一起使用。

For more refer to this post.

有关更多信息,请参阅此帖子