You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jim Sproull <ji...@sitepak.com> on 2000/06/23 17:55:24 UTC

maintaing global variable in PerlLogHandler

Hi All,

 I'm currently using mod_usertrack to maintain a session id for each
request, then am logging this with my own perl Log handler.  This is all in
and working fine (thanks to a couple members of this list - Jacob Davies and
Ian Kallen - thanks guys!).  Unfortunately, since the cookie is set on the
first request, it is impossible to determine if the client has cookies
enabled.  (And I don't want to lose the referrer, so getting the information
from the cookie header is not an option, either).  So, I'm effectively doing
both and comparing:

	my $unique_session = $r->dir_config("LogName") . "\t" .
$Logfields{'hostname'};
	$Logfields{'si-uid'} = $r->notes('cookie'); # default
	my $cookies = fetchCookies($r->header_in('Cookie'));  # internal sub that
parses cookies
	if ($cookies && ($cookies->{'sessionid'} eq $Logfields{'si-uid'})) {
		# if cookie and notes are equal,
	      # we're past 1st request and cookie are enabled
		# remove from session, we're fine
		$log->info("Cookies are equal: " . $Logfields{'si-uid'});
		set_sessionid($unique_session, undef);
	} else {
		# ok, no cookie yet
		# if it's defined in session, then it's past 1st request
		# cookies are disabled, use first request id
		my $id;
		if ($id = get_sessionid($unique_session)) {
			$log->info("Got sessionid " . $id);
			$Logfields{'si-uid'} = $id;
			# log no cookies
			$Logfields{'no_cookies'}++;
		} else {
			# first request, squirrel for next request
			$log->info("Setting sessionid to " . $Logfields{'si-uid'});
			set_sessionid($unique_session, $Logfields{'si-uid'});
		}
	}

  This all works fine. However, the get_sessionid and set_sessionid are
using a dbm file, which is locked and unlocked during each request.  (I
know, I know).  Obviously, this is a lot more load that is necessary.  I
tried using a simple global variable (defined before the handler), but this
was unreliable as it was set differently for each request.  No doubt due to
different processes handling each request.  Can anyone suggest a better way
of handling this globablly accessed data?  Thanks.

Jim Sproull
jim@sitepak.com


Re: maintaing global variable in PerlLogHandler

Posted by Jim Winstead <ji...@trainedmonkey.com>.
Attached is an updated version of the patch that should apply
to Apache 1.3.12 cleanly.

I don't know if anyone's ported the patch to 2.0. I'm not sure how
significantly, if at all, mod_usertrack has changed for 2.0.

(This has an additional feature, CookieDomainEnv, which is less
documented and probably not as completely useful as it could be.)

Jim

On Jun 24, Greg Cope wrote:
> Jim Winstead wrote:
> > 
> > On Jun 23, Jim Sproull wrote:
> > >   This all works fine. However, the get_sessionid and set_sessionid are
> > > using a dbm file, which is locked and unlocked during each request.  (I
> > > know, I know).  Obviously, this is a lot more load that is necessary.  I
> > > tried using a simple global variable (defined before the handler), but this
> > > was unreliable as it was set differently for each request.  No doubt due to
> > > different processes handling each request.  Can anyone suggest a better way
> > > of handling this globablly accessed data?  Thanks.
> > 
> > If you search the new-httpd list, you should be able to find a
> > patch I posted to mod_usertrack (quite some time ago) that in
> > addition to adding a configuration option (to set the cookie's
> > domain or something like that), makes mod_usertrack create two
> > additional notes -- "out-cookie" and "in-cookie" which are set to
> > the value of its session cookie depending on whether it is outgoing
> > (being set) or incoming (subsequent requests).
> 
> This is just what I've been after (the domain and cookie set checking) -
> thanks.
> 
> Has anyone an issues with using this apache module with mod_perl.  I
> need to track users via cookies on a site that is 1/2 html and half
> mod_perl - hence this offers an ideal solution for cookie tracking HTML
> pages via an UID. 
> 
> Jim , all the patches that I've found from you in archives appear to be
> incomplete, I've tried fixing one but to little avail (my C is very very
> basic).
> 
> Could you post or send me the patch - would be very much appreciated!
> 
> Also does anyone know if anyone is working on an Apache 2.0 version ?
> 
> Greg Cope
> 
> > 
> > With that, it is very easy to know when the cookie is new, and if
> > you log the two fields seperately, you can easily calculate the
> > number of your visitors who have cookies disabled (or only make
> > a single request to the webserver).
> > 
> > Jim
> 

Re: maintaing global variable in PerlLogHandler

Posted by Greg Cope <gj...@rubberplant.freeserve.co.uk>.
Jim Winstead wrote:
> 
> On Jun 23, Jim Sproull wrote:
> >   This all works fine. However, the get_sessionid and set_sessionid are
> > using a dbm file, which is locked and unlocked during each request.  (I
> > know, I know).  Obviously, this is a lot more load that is necessary.  I
> > tried using a simple global variable (defined before the handler), but this
> > was unreliable as it was set differently for each request.  No doubt due to
> > different processes handling each request.  Can anyone suggest a better way
> > of handling this globablly accessed data?  Thanks.
> 
> If you search the new-httpd list, you should be able to find a
> patch I posted to mod_usertrack (quite some time ago) that in
> addition to adding a configuration option (to set the cookie's
> domain or something like that), makes mod_usertrack create two
> additional notes -- "out-cookie" and "in-cookie" which are set to
> the value of its session cookie depending on whether it is outgoing
> (being set) or incoming (subsequent requests).

This is just what I've been after (the domain and cookie set checking) -
thanks.

Has anyone an issues with using this apache module with mod_perl.  I
need to track users via cookies on a site that is 1/2 html and half
mod_perl - hence this offers an ideal solution for cookie tracking HTML
pages via an UID. 

Jim , all the patches that I've found from you in archives appear to be
incomplete, I've tried fixing one but to little avail (my C is very very
basic).

Could you post or send me the patch - would be very much appreciated!

Also does anyone know if anyone is working on an Apache 2.0 version ?

Greg Cope

> 
> With that, it is very easy to know when the cookie is new, and if
> you log the two fields seperately, you can easily calculate the
> number of your visitors who have cookies disabled (or only make
> a single request to the webserver).
> 
> Jim


Re: maintaing global variable in PerlLogHandler

Posted by Jim Winstead <ji...@trainedmonkey.com>.
On Jun 23, Jim Sproull wrote:
>   This all works fine. However, the get_sessionid and set_sessionid are
> using a dbm file, which is locked and unlocked during each request.  (I
> know, I know).  Obviously, this is a lot more load that is necessary.  I
> tried using a simple global variable (defined before the handler), but this
> was unreliable as it was set differently for each request.  No doubt due to
> different processes handling each request.  Can anyone suggest a better way
> of handling this globablly accessed data?  Thanks.

If you search the new-httpd list, you should be able to find a
patch I posted to mod_usertrack (quite some time ago) that in
addition to adding a configuration option (to set the cookie's
domain or something like that), makes mod_usertrack create two
additional notes -- "out-cookie" and "in-cookie" which are set to
the value of its session cookie depending on whether it is outgoing
(being set) or incoming (subsequent requests).

With that, it is very easy to know when the cookie is new, and if
you log the two fields seperately, you can easily calculate the
number of your visitors who have cookies disabled (or only make
a single request to the webserver).

Jim