As far as a data source, you could use anything from a flat file, to DBM, all the way to a relational database, like MySQL.

I would think your choice would be determined by a few factors:

My personal preference would be to use a database, but that's because I already have one set up, and I'm comfortable with it and DBI. I always find myself using flat files/DBM and wishing for something faster, usually not the other way around.

Whichever you choose, try and make sure your code to save "session" information to the datasource is encapsulated in an object or routine. This will make it easier on you if you need to upgrade or change your mind about the data source in the future after some live tests.

The second decistion to make is: How are you going to update the datasource each time a user goes into a different area on your site?

If you're entire site is perl driven, you might be looking at modifying all of these scripts to keep the "who is" list up-to-date every access. Depending on how many scripts their are, and how important downtime is to your users, this could be very easy to difficult.

A neat alternative would be to use something called a Web Bug to track your users through your site. A web bug is simply an 1 x 1 pixel image tag on all your HTML pages, where the src url points to a single CGI script. The CGI will be loaded along with all the other images on the page. Make sure the code in a bug uses CGI.pm's header() method, with an "expires" set to 0 seconds, so that the browser doesn't cache the image, like so:

my $cgi = CGI->new; print $cgi->header( -type => 'image/gif', -expires => '+0s', );

A good tip would be to place the web bug at the top of all your pages so it gets loaded first. AFAIK, most browsers load images based on the order they find them in the HTML. IMHO this is probably easier than changing an entire perl driven web site, since you're only editing HTML.

Disclaimer: Be careful with this though, as some people can get offended by these, as they have been known to allow easier "profiling" of people on the Internet. Also if people have thier images turned off the bug won't load, although this is probably not a really big limitation.

If speed is important to you in this case, and I think it should be, then you will want the routine that updates the user's name and last access timestamp, to do this - and only this, quickly. You probably don't want to worry about "reaping" the old sessions from the data source each time you have a request on your site. Scanning the whois list that many times is fairly inefficient.

A better idea would be to offload this onto a crontab that runs at set intervals and reaps sessions older than $mins. It is far more efficient to do it this way, because you're only doing a full whois list scan and deletion once in a while, not every request.

Hope this helps.


In reply to Re: A Time Stamp problem by dkubb
in thread A Time Stamp problem by tanger

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.