Hi everyone. I realized the close() method was deprecated with flush when reading the docs. I remember actually using flush() first just to see if it would get rid of the error, then decided to try close for the heck of it.

As with jZed, I'll take your advice and try to better indent my coding.

I decided not to use cookies and have it keep loading the session via db (sessions expire after 30mins no matter what..this app will not be used my many).

Kurt, I think I know what you mean. I can prob modify CGI::Session so that it adds a expire_time field to the database, and then I can just check against that time vs, the E_TIME stored by CGI::Session. I think I read an example here, Re: Listing Active CGI::Sessions, before writing this little cron script.

I was going to do this option, but thought it wasn't too necessary if I could get my first method right.

I fixed my following code so it looks like this:
use DBI; my $dbh = DBI->connect($main::location, $main::user, $main::ba_pas +s, { RaiseError => 1, AutoCommit => 1}) or die "Couldn't connect to d +atabase: " . $DBI::errstr; eval { my $sth= $dbh->prepare("SELECT id FROM sessions"); my $id; $sth->execute(); $sth->bind_columns(undef, \$id); require CGI::Session; import CGI::Session; while ($sth->fetch()) { my $session = CGI::Session->load("driver:MySQL", $id, {Handle=>$ +dbh}); next if $session->is_empty; if (($session->ctime + $session->etime) <= time()) { $session->delete(); } } }; if ($@) { print $@; $dbh->disconnect(); }
Still a bit concerned since it doesn't have $dbh->disconnect anymore inside the eval. I'm relying on it existing and disconnecting when it detects the end of my script. The above code generates no errors or warnings and my cron script can run w/out e-mailing me the output of the error all the time. At most, it will only detect about 3-20 sessions a given day.

Notice I still use the load method vs. the new method of CGI::Session. I thought the load method was intentionally for this purpose (to only load and read vs, using new to create/edit/append).

From the CGI::Session manual:
load() is useful to detect expired or non-existing sessions without forcing the library to create new sessions.

Also , I hope my indenting is a bit better. :)

In reply to Re: CGI::Session disconnect invalidates 1 active statement handle by perleager
in thread CGI::Session disconnect invalidates 1 active statement handle by perleager

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.