Sessions on (mt) Media Temple’s (gs) Grid-Server
24th of April, 2007 Hosting , php ,
Not long ago, I uploaded latest version of a project I'm working on to my production server at (mt) Media Temple, only to discover that users were kicked out of the system no less than five seconds after logging in.
At first I didn't know what was causing this, so I went through most of my code, searching every tidbit of it in an attempt to find out what was causing this unexpected behaviour. I searched for possible reasons to such an "time out", but couldn't find anything that even seemed remotely plausible. After staring at my code for quite some time, it dawned on me; because of the sheer number of sites hosted at (mt) Media Temple and their (gs) Grid-Server cluster, even with the default settings the sessions initiated would be cleared out and deleted before the users would be able to do anything.
I tried to set the session.gc_probability higher, which didn't work. The same with the lifetime of each session, using the session.gc_maxlifetime, which controls when a session is to be deleted.
The solution
After some more research, I found some rather massive scripts that kept track of sessions using tables and some other really paranoid measures. The solution, however, is actually quite simple, and is stated in the manual as well:
Note: If different scripts have different values of
session.gc_maxlifetimebut share the same place for storing the session data then the script with the minimum value will be cleaning the data. In this case, use this directive together with session.save_path.1
Here is what I did
- Created a directory called
sessionsone level above myhtml-catalogue - Added the following lines to my scripts
< ?php
ini_set('session.gc_maxlifetime', 3600); // Valid for an hour
session_save_path('/sessions/'); // Relative to file system, not URI
session_start();
?>
Anyone know of a better way to solve this issue?
1PHP: Session Handling Functions - gc_maxlifetime

5 Responses to “Sessions on (mt) Media Temple’s (gs) Grid-Server”
We actually have a documented workaround to this issue. Essentially, it gets the same job done but does not require an ini_set parameter to be passed. Our recommended approach is by adding a line to your php.ini file so set a different sessions save path. Check out this KB article for specific instructions: http://kb.mediatemple.net/article.php?id=235
=)
–Arman.
1Have you tried the solution listed in the (mt) KnowledgeBase?
http://kb.mediatemple.net/article.php?id=235
You can make a similar change to your php.ini on the Grid which will keep you from having to track it down multiple times in code.
2How cool is that?! The folks at Media Temple actually responding to this issue - and soon too. Kudos guys!
3Your suggestion worked for me - thank you! I tried the procedure from MT’s knowledgebase, and it didn’t work for me on the 2 sites/scripts I tried it on. I still love MT, though!
4Hooray! This problem has cost me soooo many hours of trial and error testing to try and figure out a solution. I tried the KnowledgeBase answer months ago, and it worked for about a day at the most, then stopped. Your solution is working now (hopefully it’ll stay that way… ;P), tho I found I had to use a more specific path (/home/xxxx/data/sessions) to get it to work.
Wow. I even paid for a (dv) server to try and solve this problem, as getting logged out all the time was totally winding up my clients and making me look foolish.
5