php 为什么标准会话生存期是 24 分钟(1440 秒)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14703363/
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
Why is the standard session lifetime 24 minutes (1440 seconds)?
提问by Anna V?lkl
I've been doing some research on PHP Session Handling and came across the session.gc_maxlifetimevalue of 1440 seconds.
I've been wondering why the standard value is 1440 and how it is calculated?
What is the basis for this calculation?
我一直在对 PHP 会话处理进行一些研究,并发现了session.gc_maxlifetime1440 秒的值。我一直想知道为什么标准值是 1440 以及它是如何计算的?这个计算的依据是什么?
How long does it make sense to keep sessions? What min/max values for session.gc_maxlifetime would you recommend? The higher the value, the more vulnerable the Web-App is for Session HiHymaning, I'd say.
保持会话多久才有意义?你会推荐 session.gc_maxlifetime 的最小/最大值是多少?我会说,该值越高,Web 应用程序越容易受到会话劫持。
回答by CXJ
The real answer is probably very close to this:
真正的答案可能与此非常接近:
Back during PHP3 days, PHP itself had no session support.
在 PHP3 时代,PHP 本身没有会话支持。
But an open-source library called PHPLIB, initially written by Boris Erdmann and Kristian Koehntopp from NetUSE AG, provided sessions via PHP3 code.
但是一个名为 PHPLIB 的开源库,最初由来自 NetUSE AG 的 Boris Erdmann 和 Kristian Koehntopp 编写,通过 PHP3 代码提供会话。
Session lifetimes were defined in minutes, not seconds. And the default lifetime was 1440 minutes, or exactly one day. Here's that line of code from PHPLIB:
会话生存期以分钟为单位定义,而不是秒。默认的生命周期是 1440 分钟,也就是一天。这是来自 PHPLIB 的那行代码:
var $gc_time = 1440; ## Purge all session data older than 1440 minutes.
Sascha Schumann was involved with the PHPLIB project around the period of 1998 to 2000. There's no doubt he was familiar with the PHP3 session code.
Sascha Schumann 大约在 1998 年到 2000 年期间参与了 PHPLIB 项目。毫无疑问,他熟悉 PHP3 会话代码。
Then PHP4 came out in the year 2000 with native session support, but now the lifetime was specified in seconds.
然后 PHP4 于 2000 年推出,支持本地会话,但现在生命周期以秒为单位指定。
I'll bet someone just never bothered converting minutes to seconds. It's probable that person was Sascha Schumann. Once that value was coded into the Zend engine, it became the configuration (php.ini) default as well.
我敢打赌,有人从不费心将分钟转换为秒。这个人很可能是萨沙舒曼。一旦该值被编码到 Zend 引擎中,它也成为配置 ( php.ini) 默认值。
回答by Steve Terjeson
1440 is used in a time calculation turning seconds into hours/days.
1440 用于将秒转换为小时/天的时间计算。
- 1 day = 24 hours ( hours * 24 = 1 day )
- day = 1440 minutes ( minutes * 60 * 24 = 1 day )
- day = 86400 seconds ( seconds * 60 * 1440 = 1 day )
- 1 天 = 24 小时(小时 * 24 = 1 天)
- 天 = 1440 分钟(分钟 * 60 * 24 = 1 天)
- 天 = 86400 秒(秒 * 60 * 1440 = 1 天)
Example:
例子:
9 days [* 60] = 540 [* 1440] = 777600 seconds
9 天 [* 60] = 540 [* 1440] = 777600 秒
The same is true in reverse:
反过来也是一样:
777600 seconds [/ 1440] = 540 [/ 60] = 9 days
777600 秒 [/ 1440] = 540 [/ 60] = 9 天

