Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with /tmp folder and session variable...help!

Status
Not open for further replies.

spewn

Programmer
May 7, 2001
1,034
i have been using this format to set and maintain session variables:

Code:
$cgi = new CGI;
$sid = $cgi->cookie("CGISESSID") || undef;
$session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
$cookie = $cgi->cookie(CGISESSID => $session->id);
$sSid = $session->id();

so far this works great. but today i moved my files to a new hosting company, and i'm running into an issue with the session maintaining for any period of time...sometimes the session will last for minutes or hours, and sometimes it doesn't maintain at all.

after several trial and error runs, i have realized that it's this piece of code:

Code:
{Directory=>'/tmp'}

i figured this out by changing the '/tmp' to 'stemp', and the session maintains just fine.

the problem is that '/tmp' seems to be a directory on the server, but isn't in my file tree, while 'stemp' is an actual folder on my file tree.

although this fix works, the 'stemp' folder will eventually be clogged with thousands of session files.

i'm not too familiar with server setups, so i don't know if '/tmp' is a real folder location, or just a reference to a temporary folder, and if so, maybe the hosting company i'm with uses something differently.

any ideas?

thanks!

- g
 
Just add code to your session creation page that blow away files older than x amount of time (what ever your maximum session is). I think the examples in the cookbook have it do this randomly (so it doesn't check every time.. just every so often)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
/tmp is the universally-writeable temporary directory in Unix or Linux. It usually gets cleared out periodically by a scheduled (cron) script.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
In Solaris anything in /tmp (by default) is actually loaded into memory, a lot of Admin's do not want it used for anything unless you know what your doing. It isn't like that on HP and I have not checked other Unix's but I have NEVER seen this on a linux box. Most hosting providers don't want any cross contamination of sites and won't let you access things like /tmp anyway, they will want you to use /var/apache/ and handle the cleanups yourself.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top