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
)
} );
|
- Adding values to Session file Differentiated Software Solutions Pvt. Ltd
- RE: Adding values to Sessi... Bogomolnyi Constantin
- RE: Adding values to Sessi... Jerrad Pierce