NAME
CGI::Session::DB2 - DB2 driver for CGI::Session
SYNOPSIS
use CGI::Session;
$session = new CGI::Session("driver:DB2", undef, {DB=>'dbname', Schema=>'cgisess',Table=>'cgisess'});
For more examples, consult CGI::Session manual
DESCRIPTION
CGI::Session::DB2 is a CGI::Session driver to store session data in a DB2 table. To write your own drivers for CGI::Session refere CGI::Session manual.
Options accepted:
- Database
-
Database name to use. Defaults to 'cgisess'.
- DB2Driver
-
DB2::db object or package to latch on to, rather than using the internal version. Will simply add the internal table to the existing DB2::db object.
- Table
-
Table name to use. Defaults to 'cgisess'.
- Schema
-
Schema name to use. Defaults to 'cgisess'.
- UserName
-
User name for authentication
- UserPW
-
User password for authentication
STORAGE
To store session data in a DB2 database, you first need to create a suitable table for it with the following command:
perl -MCGI::Session::DB2 -e 'CGI::Session::DB2->create(DBName=>q[dbname],Schema=>q[cgisess],Table=>q[cgisess])'
All other CGI::Session options documented for use with CGI::Session::DB2 are valid here - it is recommended that you put your options into a hash somewhere in your code, and accept a setup or create option that would simply reuse that hash in calling create.
my $options = {
DBName => q[web],
Schema => q[cgisess],
Table => q[cgisess],
};
if ($ARGV[0] and $ARGV[0] eq 'create')
{
CGI::Session::DB2->create($options);
exit(0);
}
my $session = new CGI::Session('driver:DB2', $query, $options);
# ...
Obviously, this is not something you do right away - you need to make a few decisions first, such as what database to use, schema, etc. Also note that this create option will only create a local database. I'm not sure that DB2 supports creating remote databases. However, if your database already is remote, and cataloged locally, the create option may be able to create the table for you.
In the remote database case, the DBName should be the locally cataloged name, which is not necessarily the same as the remote database name.
For more information on database creation, see DB2::db
. Also note DB2::db's requirement for DB2INSTANCE to be set. You will need to set this in your own application script(s).
CLEANUP
CGI::Session does not seem to provide a way to automatically clean up old (expired) sessions unless they happen to get re-used somehow. CGI::Session::DB2 has decided to implement saving an entire session's expiry as another column in the database table, using the timestamp type. This should allow clean up to be as simple as:
if ($ARGV[0] and $ARGV[0] eq 'cleanup')
{
CGI::Session::DB2->cleanup($options);
exit(0);
}
Call the cleanup option in a cron job or something, and everything should be cleaned up such that only sessions that are still valid would still exist.
COPYRIGHT
Copyright (C) 2004 Darin McBride. All rights reserved.
This library is free software and can be modified and distributed under the same terms as Perl itself.
AUTHOR
Darin McBride <dmcbride@cpan.org>
SEE ALSO
CGI::Session - CGI::Session manual
CGI::Session::Tutorial - extended CGI::Session manual
CGI::Session::CookBook - practical solutions for real life problems
RFC 2965 - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt
CGI - standard CGI library
Apache::Session - another fine alternative to CGI::Session