PHP会话过期太早 [英] PHP Sessions expire too soon
问题描述
我正在VPS上运行带有Nginx服务器和PHP Fastcgi的网站.我试图配置php.ini(在/etc/php5/cgi中)以使PHP会话持续超过3天(259200秒),但是它不起作用,并且我的php会话持续不超过一小时.
I'm running a website with a nginx server with PHP Fastcgi on a VPS. I tried to configure the php.ini (in /etc/php5/cgi) to have PHP session last longer than 3 days (259200 seconds), but it didn't work and my php sessions don't last more than one hour.
我当前在php.ini中的会话配置:
My current session config in the php.ini:
session.use_cookies = 1
session.use_only_cookies = 1
session.name = PHPSESSID
session.auto_start = 0
session.cookie_lifetime = 259200
session.cookie_path = /
session.cookie_domain =
session.cookie_httponly =
session.serialize_handler = php
session.gc_probability = 1
session.gc_divisor = 1000
session.gc_maxlifetime = 259200
session.bug_compat_42 = Off
session.bug_compat_warn = Off
session.referer_check =
session.entropy_length = 0
session.cache_limiter = nocache
session.cache_expire = 259200
session.use_trans_sid = 0
session.hash_function = 0
这里可能是什么问题?
推荐答案
这听起来有点像服务器上的Ubuntu或Debian.如果我正确地记住了某个地方(通过php5或php5-common软件包安装)的cronjob,它会更频繁地清理您的会话目录.
This sounds a bit like Ubuntu or Debian on the server. If I rememeber correctly there is a cronjob somewhere (installed either by the php5 or the php5-common package) which cleans out your session directory more often.
我建议您将会话配置为保存在其他位置(默认设置除外).调整session.save_path
并确认cronjob没有将其清空.
I'd recommend you configure your sessions to be saved somewhere else (than the default). Adjust session.save_path
and verify to cronjob doesn't empty it.
cronjob位于/etc/cron.d/php
之类的位置-可以肯定地运行dpkg -L php5
或dpkg -L php5-common
.假设您使用的是Ubuntu(或Debian),则应显示所有已安装文件的位置.
The cronjob is somewhere like /etc/cron.d/php
- to be certain, run dpkg -L php5
or dpkg -L php5-common
. Assuming you are on Ubuntu (or Debian) this should show you the location of all installed files.
这篇关于PHP会话过期太早的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!