Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number


by Anonymous Monk
on Jul 21, 2003 at 16:12 UTC ( #276341=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I have 2 questions.

1. Can CGI::Session be reliable for a site handling 1 - 5 million people. (If yes how would you recommend I implement it.)

2. I am currently implmenting the CGI::Session using the MySQL driver storing the sessions in a field in the database. I then set a client side cookie with the session ID and check the session ID against each page the user is viewing. My question is how do you get the row to delete from the table if you set the expiration time on the session and the session has expired? Is there a way to do this?

Replies are listed 'Best First'.
Re: CGI::Session
by antirice (Priest) on Jul 21, 2003 at 17:08 UTC

    1. It depends.

    2. You can either edit CGI::Session::MySQL or edit your own (I called mine pun intended). You will need the following table created in your database:

    CREATE TABLE sessions ( id CHAR(32) NOT NULL UNIQUE, a_session TEXT NOT NULL, expires int unsigned NOT NULL );

    You will also need to alter the store sub in your package.

    sub store { my ($self, $sid, $options, $data) = @_; my $dbh = $self->MySQL_dbh($options); my $lck_status = $dbh->selectrow_array(qq|SELECT GET_LOCK("$sid", +10)|); unless ( $lck_status == 1 ) { $self->error("Couldn't acquire lock on id '$sid'. Lock status: + $lck_status"); return undef; } $dbh->do(qq|REPLACE INTO $TABLE_NAME (id, a_session, expires) VALU +ES(?,?,?)|, undef, $sid, $self->freeze($data),$self->expire() + $self +->atime()); return $dbh->selectrow_array(qq|SELECT RELEASE_LOCK("$sid")|); }

    Now in your code for clearing out the expired session id's, run this do:

    $dbh->do("delete from sessions where expires<?",undef,time());

    Just be certain to set $session->expire() to something or it will never get deleted. Hope this helps.

    The first rule of Perl club is - use Perl
    ith rule of Perl club is - follow rule i - 1 for i > 1

Re: CGI::Session
by Abstraction (Friar) on Jul 21, 2003 at 16:49 UTC
    1. Is that 1 - 5 million people per day? or total users?

    2. I haven't used CGI::Session yet so someone may have CGI::Session specific advice. However what I would do is give each row in my table a date field that holds the expiration date for the session. Then in a cron job, run a script that deletes all rows that have expired session dates.

      1. 1 - 5 million total users.

      2. I was wondering if there was a built in feature in CGI::Session that removes the row, after the expiration date had expire.

Re: CGI::Session
by jryan (Vicar) on Jul 21, 2003 at 19:45 UTC

    Could you be a little more specific as to what "1 - 5 million people" means?

    I assume that you are using mod_perl as the backend, and mod_perl can certainly handle that type of load (see mod_perl Success Stories if you don't believe me). However, without more details about your site, it is hard to say for sure.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://276341]
Approved by diotalevi
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2023-11-30 10:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found