CGI-Session-Driver-flexmysql

 view release on metacpan or  search on metacpan

lib/CGI/Session/Driver/flexmysql.pm  view on Meta::CPAN

storing any sessions at all --  but I have a use for it, so it's here for you too.

I often store sessions directly on my user table to make sure that when a user
logs in, s/he can always pick up where s/he left off even if logging in from
a different browser, after erasing cookies, etc.  I do this by specifying the 
Table and KeyField options.  Since the user table already has one row for each
user, and since I use the email address of the user as the KeyField, I do NOT
want FlexMySQL to create new rows in my user table and put some random MD5 string
as the email address.  So I specify:

   NoInsert => 1

And this makes FlexMySQL use an UPDATE statement instead of a REPLACE INTO statement,
which guarantees that if the claimed session id doesn't exist in the table, it
won't be created.

=head2 NoDelete => 1

Same scenario as above -- for most applications where you're generating random
session ids and inserting rows into a table, you don't want this option because
it means that you can't delete sessions except with an external script.

However, I have a use for it:  if I call  $session->delete() I want it to delete
the session, but since my sessions are often stored in my user table, I do NOT
want it to delete the entire row!   Using this option effectively makes C<delete>
the same as C<clear> (well, almost)  because when you specify NoDelete => 1, FlexMySQL
updates the database field and sets it to NULL, whereas with C<clear> all the
session fields are cleared but the session object itself is still stored in your
table's data field).

=head2 NoReplace => 1

Use this option when you want to use INSERT and UPDATE statements instead of a
REPLACE statement to store sessions.

Thanks to Simon Rees for suggesting this option. 

=head2 AutoCreate => 1

If you specify this option, FlexMySQL will automatically create a table for 
session storage if one does not already exist. If you specified any customization
such as table name, key field, etc.  it is used to create the table.  

=head1 LOCKING

GET_LOCK and RELEASE_LOCK work on a server-wide basis. If we acquire
a lock on some 32-character id for the purpose of sessions, no other
application can use locking with 32-character id's generated in the
same way (MD5) because there might be a very accidental overlap, which
could really screw things up depending on what that other application
is doing. In general, session data is not important and we can assume
all other applications should have priority with regard to everything.
Also, even though CGI::Session::MySQL obtains the locks, it would still
overwrite the data as soon as the "other thread" releases its lock,
which means that if two clients are using the same session id, the
locking gives absolutely no protection. MySQL already guranatees that
data is not corrupted when we update the same row from different
places at nearly the same time because it uses a queue for the requests.
It would be different if, once it detected that there is a lock, it
read the data again and SYNCHRONIZED it before updating. Then locking
would be helpful because no other client could synchronize at the same
time. But CGI::Session::MySQL doesn't actually do anything that requires
locking. 

A real use for locking would be to actually lock the session data while
the it's being used.  GET_LOCK and RELEASE_LOCK are usually not the
appropriate way to do this, especially for non-cgi applications where
the session may be in use for a considerable amount of time. I propose
that this locking be done using an extra field. GET_LOCK and RELEASE_LOCK
would be appropriate for locking the row while this extra locking field
is being checked and updated, and then this extra locking field would 
tell other processes using FlexMySQL whether they can read or write the
session data. 

Right now I don't have a need for this kind of locking, so it's not
implemented.  If you want it, you can either send me a patch or roll your
own CGI::Session subclass. Asking me very nicely will also work.

=head1 COPYRIGHT

CGI::Session::Driver::flexmysql is Copyright (C) 2004-2005 Jonathan Buhacoff.  All rights reserved.

This library is free software and can be modified and distributed under the same
terms as Perl itself. 


=head1 AUTHOR

Jonathan Buhacoff <jonathan@buhacoff.net> wrote CGI::Session::Driver::flexmysql

=head1 SEE ALSO

=over 4

=item *

L<CGI::Session::Driver::mysql|CGI::Session::Driver::mysql> - The original MySQL driver for CGI::Session
written by Sherzod Ruzmetov <sherzodr@cpan.org>. Kudos
to Sherzod for making such a great session management framework.

=item *

L<CGI::Session|CGI::Session> - CGI::Session manual

=item *

L<CGI::Session::Tutorial|CGI::Session::Tutorial> - extended CGI::Session manual

=item *

L<CGI::Session::CookBook|CGI::Session::CookBook> - practical solutions for real life problems

=item *

B<RFC 2965> - "HTTP State Management Mechanism" found at ftp://ftp.isi.edu/in-notes/rfc2965.txt

=item *

L<CGI|CGI> - standard CGI library

=item *



( run in 0.563 second using v1.01-cache-2.11-cpan-9581c071862 )