Hello all,
2008/2/6, titetluc titetluc <[EMAIL PROTECTED]>: > > Oups > I answered directly to Torsten by error > Here is my answer and the reply > > 2008/2/6, Torsten Foertsch <[EMAIL PROTECTED]>: > > > > On Wed 06 Feb 2008, titetluc titetluc wrote: > > > The module I am developing has to delete the cookie if it is not > > refreshed > > > regularly. > > > The question: how can I manage this timeout inactivity ? > > > The best solution would be to use a mechanism where callbacks > > (deleting the > > > cookie rfom the database) would be called automatically on inactivity. > > > Does such an API is proposed by : > > > . the APR API > > > . mod_perl API > > > . an Apache2::xxx perl module > > > . a CPAN module > > > > > > If not, how can I solve my problem ? (I could verify regularly in the > > DB > > > storage, but this is a last resort solution. Even in this case, how > > could I > > > implement it ?) > > > > > > Apache (at least 2.2.x) implements a "monitor" hook, see > > server/mpm_common.c. > > To use this hook you'd have to write a bit XS stuff like Geoff's > > AuthenHook, ... since there is AFAIK no CPAN module. This hook is run > > from > > time to time in the parent apache. > > > > Otherwise there are 2 standard ways to do that: > > > > - a cron job or something similar in the DB itself > > - check each time in a connection cleanup handler (to do it not too > > often you > > can use a global variable that holds the timestamp of the last cleanup > > and > > run it only if the difference to the current time grows too big.) > > I am using the Apache::Session module to manage ... sessions. Apache::Session does not manage session expiration I found the following comment on the CPAN rating on Apache::Session module ( http://cpanratings.perl.org/dist/Apache-Session) Quotation: "There is no support for temporary session keys. I'd like to be able to set a key that expires in X minutes. This can be handled by writing your own wrapper that sets a special session key, but it would be nice to be in the API somewhere. I've since switched my site over to using Data::Uniqid for session ID generation and Cache::FileCache for storing temporary form data. Data::Uniqid assures me that the ID it generates is very unique, so I don't have to store every session in my database. And FileCache has the expiration support I need for holding temporary form data." I am not sure this will solve my problem, but I think this is also a good I'd go for one of the standard ways since: > > > > - easier to implement > > - your code doesn't run as root > > > > > > One naive question: how can I declare a global variable under mod_perl ? > > Each request is run with a thread and by default Perl does not share > > variables ! > > I declared my variable as shared (using the threads::shared module) but > > this declaration does not seem to be sufficient in a mod_perl > environment > > !!! > > I meant something like this: > > package My::Cleanup; > > use strict; > use Apache2::Const -compile=>('OK', 'DECLINED'); > use Apache2::RequestRec (); > use Apache2::Connection (); > use APR::Pool (); > > my $lastrun=0; # this is the global variable: one per process > my $check_interval=60; #check every minute > > sub run { > my $time=time; > if( $time>$lastrun+$check_interval ) { > $lastrun=$time; > # here you can check the modification time ((stat)[9]) of a file on > disk > # flock() it with LOCK_NB set and return if flock fails. > # alternatively you can implement an interface to apr_proc_mutex which > is > # quite easy, see ThreadMutex for example. > # or you implement $lastrun in your database. > # or you use BerkeleyDB which is actually shared memory. > > # doit > ... > } > return Apache2:Const::OK; > } > > sub handler { > my ($r)[EMAIL PROTECTED]; > unless( $r->connection->pnotes->{cleanup_installed} ) { > $r->connection->pool->cleanup_register(\&run); > $r->connection->pnotes->{cleanup_installed}=1; > } > return Apache2::Const::DECLINED; > } > > Then: > > # install it either as PerlPostReadRequestHandler or as > # PerlHeaderParserHandler > PerlInitHandler My::Cleanup > > I'd implement the process global variable as shown plus perhaps another > variable in the database if the session is stored there. It depends on how > expensive your cleanup is. > > Torsten > > Torsten > > > >