Hello ,
Your problem is an classic example of an incorrect implementation of tie function
In fact the session acts like this :
1)You tie your hash (INDIRECTLY linket to the database)
2)You put your data in the hash but it still in memory because it is quite stupid and slow to put
it directly in the database ( each time you acces the tied hash it doesn't make an SELECT from the database)
So if you stop at this point you loose all your data in memory witch is normal
So you need the step 3)
3) UNTIE you tied hash to ensure the syncronisation between your hash in memory and the database
Under apache::registry there is an very usefull thing the register_cleanup method witch have an advantage
it is executed after EACH request this is an equivalent to END block in plain cgi , this protect you against
STOP ou RELOAD actions :
Lets put it in shape:
I suppose that you use Apache::Session module
 
1)
eval {
    tie %session, 'Apache::Session::MySQL', $id, {
       DataSource => 'dbi:mysql:sessions', 
         UserName   => 'user',         
         Password   => 'password',           
         LockDataSource => 'dbi:mysql:sessions',
         LockUserName   => 'user',
         LockPassword   => 'password'}
   };    #you can deal with exceptions at this point if you want
#we have our hash tied
2)
#lets put some data
$session{data}='data';
3)
#syncronise the whole thing
$r->register_cleanup(
       sub{    
           untie %session;   #syncronise the session hash
           #put here all close statements to your database handlers ( if you need that )
        }
  );
 
----- Original Message -----
Sent: Friday, August 18, 2000 3:04 PM
Subject: Adding values to Session file

Hi,
 
We have a site where we create a session file on login and tie some values.
After a few page visits we want to add more values to the session file again using tie.
 
We find that only the first set of values get added. Subsequent values do not get added to this file.
Can somebody tell us what the problem is ??
 
Regards,
 
Murali
 
Differentiated Software Solutions Pvt. Ltd.
176, Ground Floor, 6th Main,
2nd Block, RT Nagar
Bangalore - 560032
Phone : 91 80 3431470
www.diffs-india.com

Reply via email to