Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: A Time Stamp problem

by dkubb (Deacon)
on Feb 07, 2001 at 09:52 UTC ( [id://56901]=note: print w/replies, xml ) Need Help??


in reply to A Time Stamp problem

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:

  • the speed you'll require
  • the time/ability to set up the solution

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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://56901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (1)
As of 2024-04-25 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found