jryan has asked for the wisdom of the Perl Monks concerning the following question:

I've been having a TERRIBLE time trying to get Apache::Session to work. It is not as if I am having problems with only one storage subset; I can't get ANY of them to work.

First of all, I tried using Apache::Session::File. However, I recieved an error stating

TIEHASH not found in Apache::Session::File

Next, I tried Apache::Session::MySQL. After setting up the database exactly as the instructions state, I again tried to tie. Unfortunately, I recieved yet another error message; method get_lock_manager does not exist in object  at /usr/lib/perl5/site_perl/5.6.0/Apache/Session.pm line 542 After examining the source, I discovered that the suspect line in question was indeed attempting to call a method named get_lock_manager, and that it did not exist.

Finally, I tried using Apache::Session::DBI. This seemed more promising, as the error I recieved was:

Permission denied at /usr/lib/perl5/site_perl/5.6.0/Apache/Session/Sys +VSemaphoreLocker.pm line 46.
Upon examination of the code, the suspect line is:
$self->{sem} = new IPC::Semaphore($self->{sem_key}, $self->{nsems}, IP +C_CREAT | S_IRWXU) || die $!;
In particular, the permissions argument: IPC_CREAT | S_IRWXU. First of all, I don't understand why database storage needs to use Semaphores, and secondly, why it doesn't work.

I've spent oodles of time trying to get Apache::Session to work, and I am having incredible urges to simply try to roll my own in order to get the functionality I want. I am using the sample scripts included with the distribution (dBs modifed to point to actual locations, of course), so I know I am not doing anything too outrageous. Does anyone have any clue of what I am doing wrong?

Replies are listed 'Best First'.
Re: Problems with Apache::Session
by IlyaM (Parson) on Dec 21, 2001 at 23:53 UTC
    First of all show your code. It is hard to say what's wrong with it without seeing it.

    As for semaphores and databases. Apache::Session have to searilize access to session object to prevent two different processes from trying to use one session at same time. One of supported methods of syncronization is semaphores.

    BTW are sure that you have latest version of Apache::Session? AFAIK Apache::Session::DBI was removed from latest version of Apache::Session.

    --
    Ilya Martynov (http://martynov.org/)

      I am using version 1.54, the latest version from CPAN. If there is a more advanced version, I am not aware of it.

      Apache::Session::DBI did require a separate install; however, most of the tutorials that I found on the web used Apache::Session::DBI as the basis.

      As for the sample code, I am using the bare minimum sample code shown in the pod documentation. At any rate, here it is, for those who do not have the module downloaded (note: $id is a varible passed through the query string; it is paramed in using the CGI module):

      For Apache::Session::MySQL

      my $dbh=DBI->connect("DBI:mysql:database=sessions;host=localhost","roo +t", ""); my $opts = {Handle => $dbh}; tie my %session, 'Apache::Session::MySQL', $id, $opts;

      For Apache::Session::DBI

      my $ops = { DataSource => 'dbi:mysql:sessions', UserName => 'root', Password => '' }; tie my %session, 'Apache::Session::DBI', $id, $opts;