I have an interesting issue which I am not sure if it is a bug or by design. I am using a database table to store sessions and I noticed that sessions are not always updated in the database. After some investigation I found some interesting observations where sessions were updated but the updates were not recorded in the database. There is too much code to paste here but I will try explain what is happening hoping that someone may be able to shed some light on the issue. Basically I am using a framework where the index file calls a bootstrapper that sets up the config & sessions, then a front controller that shows the page. In the index file, bootstrapper and front controller, session values that are set work correctly, that is they are stored in the session and database table. However this is where the fun begins. In the front controller I include the action pages and views of the modules that have been called. They are simply script pages that contain additional code for the page module. If I set session values in the included files, they are included in $_SESSION but not written to the database. Also if I use is_dir or file exists to check if a directory or file exists, it stops writing sessions to the database following the check and within the condition parenthesis, for example, in the following code "start, dir & end" should be recorded in session variables and recorded in the database table:
Code: Select all
$directory = 'c:\temp';
$_SESSION['registry']->start = 'start';
if (is_dir($directory))
{
// directory does exist
$_SESSION['registry']->dir = $this->directory;
}
$_SESSION['registry']->end = 'end';
In this case start, dir, end are recorded in $_SESSION, but only start & end are recorded in the database. also tried this way:
Code: Select all
$dir = is_dir($directory);
if ($dir) { ......
However, if I don't use a variable for the directory, it works fine writing start, dir and end to the database, eg:
And this also works:
Code: Select all
$dir = true;
if (!(is_dir($directory))) $dir = false;
if ($dir) { ......
All 3 sessions are written to the database in the above example.
This testing on a windows development PC using xampp 1.7.2 so not sure if that has anything to do with it. Xampp is using php 5.3.0 and MySql 5.
Has anyone come across this issue before? Is there some sort of depth limit for database sessions? What gets me is the sessions are recorded correctly in $_SESSIONs but just not getting updated in the database in the above conditions. I also tried to recreate the sessions at the end of the script by reading the session into an array, then rewriting back out to the session, for example:
$registry_items = $_SESSION['registry'];
unset($_SESSION['registry']);
$_SESSION['registry'] = new Registry(); //Local class with basic session helper eg set, get etc
foreach ($registry_items as $key => $value)
{
Registry::set($key, $value); // same as $_SESSION['registry']->$key = $value;
}
Interestingly enough, this will write all the sessions except those set in the included file even though they are unset and rewritten. I am pulling my hair out over this......
Happy to attach the session files if anyone can help.