我陷入了一个 $_SESSION
问题,而 $_SESSION
正在随机丢失数据。
我有一份有不同网页的表格,用户有具体时间浏览所有网页。
所以我在第一页上设置了一个会话变量, 并检查其他变量。
< 加强> start.php 加强 >
<?php
session_start();
//Set Variable for Starting application
if (!isset($_SESSION[ STARTED ])){
$_SESSION[ STARTED ] = time();
}
< 加强>app_init.php 强>
<?php
session_start();
if ((!isset($_SESSION[ STARTED ])) || (time() - $_SESSION[ STARTED ] > MAX_TIMELIMIT)) {
echo <!-- st: .$_SESSION[ STARTED ]. --> ;
// Started Variable is not set or timelimit is over.
session_destroy(); // destroy session data in storage
session_unset(); // unset $_SESSION variable for the runtime
showTimeout( 0 ); // show timeout
}
<强 > 启动页面后: 强>
<?php
// get basic settings for applications
require_once (MODEL_PATH. /app_init.php );
整个系统对本地安装、 开发服务器和测试服务器运作良好。 在生产服务器上, 我在不同的时间得到一个超时, 时间从 30 秒到 10 分钟不等 。 MAX_ TIMELIMIT < / code> 是 20 分钟 。 在这种情况下,
$_ SESSION[STAMED] code> 总是空的。 在其它环境中, 它设置正确, 即使超时时间在 20 分钟后 。
Additonal 信息 :
- It doesn t matter if I try to reach the next page or if I simply reload the actual page, I always get the timeout.
- I already checked
php.ini
on any environment ->session.save_path
is correctly set,session.cookie_lifetime
is 0 andsession.gc_maxlifetime
is 1440 - Diskspace is fine (> 22 GB free)
- Every File is on the same server and has the same url (except the last part wich specifies the step of the form. Looks like this:
host/some/path/calc -> host/some/path/form -> host/some/path/summary -> host/some/path/send - The session is set on the calc page and the timeout can happen on every page (calc, form, summary)
- I got the php.ini from production server and took it into my local workspace. After changing some paths (extensions-path, session.save_path, tmp-path) it worked very well on my local installation.
- Protocol is an all pages the same
- To recreate the session (via
$tmp
andsession_destroy()
,session_create()
) did not help - Single Frontend, no Loadbalancer (simply one apache)
- Session Files are deleted somehow
在增加一些产出和重新测试后,我得到以下信息:
- I load the Page (first step)
- I go through the form to any step (calc / form / summary)
当页面被装入
$_SESSION
时array ( STARTED => 1338298801, S_SID_ => 41554681145546 , S_LC_ => de , version_testing => 1, )
我每30秒重新上传一页
至少3分钟后(也可能是30秒)我得到超时,
$_SESSION
是:array ( )
如果我在第一个页面上尝试这个, 我会在
$_SESSION
中找到一个新的值, 因为会话数据是空的, 自动新设置 。记住:在测试/Dev环境中,会话数据仍然存在,甚至超时20分钟后也会发生。
更改会话。 saave_ path 似乎首先有效( 会话至少持续24分钟 ) 。 但一小时后, 问题还是一样。 没有会话持续时间超过4分钟 。
Problem found (but no solution yet)
Today I got Access to Production-Server and I found out, the folder with Session-Data is cleaned up after 3-5 minutes. No file there has a timestamp older than 3 minutes.
As mentioned before, PHP is correctly set (GC lifetime), and I didnt found any windows job, or something similar what is deleting these files. As PHP.ini is set correctly, I ll try to handle the session via database.
谢谢你的帮助