我在 PHP 应用程序中遇到了一些会话超时问题,我怀疑超时是由代码给出的,但我更喜欢先检查基础架构。我运行的应用程序是 Apache 上的纯 PHP 5.6,位于 AWS 中的经典 LB 后面。开发人员告诉我,他们不会在代码中操纵会话 cookie,所以我检查了我的 apache2/php.ini 文件。这是其中一个:
[Session]
session.save_handler = files
session.use_strict_mode = 0
session.use_cookies = 1
session.cookie_secure = On
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 0
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly = 1
session.serialize_handler = php
session.gc_probability = 0
session.gc_divisor = 1000
session.gc_maxlifetime = 2400
session.referer_check =
session.cache_limiter = nocache
session.cache_expire = 180
session.use_trans_sid = 0
session.hash_function = 0
session.hash_bits_per_character = 5
url_rewriter.tags = "a=href,area=href,frame=src,input=src,form=fakeentry"
为了以防万一,这是主要的 [PHP] 部分:
[PHP]
engine = On
short_open_tag = On
asp_tags = Off
precision = 14
output_buffering = 4096
zlib.output_compression = Off
implicit_flush = Off
unserialize_callback_func =
serialize_precision = 17
disable_functions = pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,
disable_classes =
zend.enable_gc = On
expose_php = Off
max_execution_time = 30
max_input_time = 60
memory_limit = 128M
error_reporting = E_ALL
display_errors = On
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = Off
html_errors = On
variables_order = "GPCS"
request_order = "GP"
register_argc_argv = Off
auto_globals_jit = On
post_max_size = 800M
auto_prepend_file =
auto_append_file =
default_mimetype = "text/html"
default_charset = "UTF-8"
doc_root =
user_dir =
enable_dl = Off
file_uploads = On
upload_max_filesize = 750M
max_file_uploads = 20
allow_url_fopen = On
allow_url_include = Off
default_socket_timeout = 60
就我而言,基础设施中绝对没有任何东西可以造成超时。我说得对吗?
我还检查了浏览器上的 cookie,并收到了以下参数:
AWSELB PHPSESSID
两种 cookie 的 Expires / Max Age 中都有此内容 --> 1969-12-31T23:59:59.000Z
我还需要检查其他东西吗?有什么线索吗?
提前致谢..
答案1
明白了!显然有一个名为 php 的 cron.d 文件,它本质上是一个 dash 脚本 (/bin/sh),每 30 分钟执行一次并清理 php 会话,此脚本评估 apache2 和 cli 配置,因此,通过修改 GC 最大生存期上的两个值即可解决问题。
答案2
为了正确处理会话,请看一下:http://php.net/manual/en/session.configuration.php
在那里你会发现这些变量:
- session.gc_probability
- 会话 gc_divisor
- 会话 gc_maxlifetime