php 我的会议将持续多久?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1516266/
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 02:54:30  来源:igfitidea点击:

How long will my session last?

phpsessiontimeout

提问by Keith Donegan

Can someone please tell me how long my session will last from the data below? - I'm not sure which one tells me

有人可以通过下面的数据告诉我我的会话将持续多长时间吗?- 我不确定是哪一位告诉我的

session.auto_start  Off Off
session.bug_compat_42   Off Off
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  1000    1000
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /var/lib/php/session    /var/lib/php/session
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    Off Off
session.use_trans_sid   0   0

回答by Gumbo

In general you can say session.gc_maxlifetimespecifies the maximum lifetime since the last change of your session data (notthe last time session_startwas called!). But PHP's session handling is a little bit more complicated.

一般来说,您可以说session.gc_maxlifetime指定自上次更改会话数据以来的最大生命周期(不是最后一次session_start被调用!)。但是 PHP 的会话处理稍微复杂一些。

Because the session data is removed by a garbage collector that is only called by session_startwith a probability of session.gc_probabilitydevided by session.gc_divisor. The default values are 1 and 100, so the garbage collector is only started in only 1% of all session_startcalls. That means even if the the session is already timed out in theory (the session data had been changed more than session.gc_maxlifetimeseconds ago), the session data can be used longer than that.

因为会话数据被垃圾收集器删除,垃圾收集器仅以session.gc_probabilitysession.gc_divisorsession_start划分的概率调用。默认值为 1 和 100,因此垃圾收集器仅在所有调用的1% 中启动。这意味着即使会话理论上已经超时(会话数据已更改超过session.gc_maxlifetime秒前),会话数据可以使用更长的时间。session_start

Because of that fact I recommend you to implement your own session timeout mechanism. See my answer to How do I expire a PHP session after 30 minutes?for more details.

因此,我建议您实现自己的会话超时机制。请参阅我对如何在 30 分钟后使 PHP 会话过期?更多细节。

回答by Luká? Lalinsky

This is the one. The session will last for 1440 seconds (24 minutes).

这是一个。会话将持续 1440 秒(24 分钟)。

session.gc_maxlifetime  1440    1440

回答by ?ystein Riiser Gundersen

If session.cookie_lifetimeis 0, the session cookie lives until the browser is quit.

如果session.cookie_lifetime是 0,会话 cookie 会一直存在,直到浏览器退出。

EDIT: Others have mentioned the session.gc_maxlifetimesetting. When session garbage collection occurs, the garbage collector will delete any session data that has not been accessed in longer than session.gc_maxlifetimeseconds. To set the time-to-live for the session cookie, call session_set_cookie_params()or define the session.cookie_lifetimePHP setting. If this setting is greater than session.gc_maxlifetime, you should increase session.gc_maxlifetimeto a value greater than or equal to the cookie lifetime to ensure that your sessions won't expire.

编辑:其他人提到了session.gc_maxlifetime设置。当会话垃圾收集发生时,垃圾收集器将删除任何超过session.gc_maxlifetime秒没有访问过的会话数据。要设置会话 cookie 的生存时间,请调用session_set_cookie_params()或定义session.cookie_lifetimePHP 设置。如果此设置大于 session.gc_maxlifetime,您应该增加session.gc_maxlifetime一个大于或等于 cookie 生存期的值,以确保您的会话不会过期。

回答by svens

You're searching for gc_maxlifetime, see http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetimefor a description.

您正在搜索 gc_maxlifetime,请参阅http://php.net/manual/en/session.configuration.php#ini.session.gc-maxlifetime以获取说明。

Your session will last 1440 seconds which is 24 minutes (default).

您的会话将持续 1440 秒,即 24 分钟(默认)。