RE: $r->document_root

[prev] [thread] [next] [Date index for 2005/02/15]

From: Cahill, Earl
Subject: RE: $r->document_root
Date: 20:43 on 15 Feb 2005
Thanks.  Using prefork looks like a winner.  After running 

apt-get install apache2-mpm-prefork apache2-prefork-dev

My final results look like 

in /etc/apache2/httpd.conf

PerlModule DocRoot
PerlTransHandler DocRoot

in DocRoot.pm I have

package DocRoot;

use strict;
use warnings;

use Apache::RequestRec ();
use Apache::RequestUtil ();
use Apache::Const -compile => qw(DECLINED);

sub handler {
  my $r = shift;
  my $new_docroot = hostname2docroot($r->hostname);
  $r->document_root($new_docroot);
  return Apache::DECLINED;
}

sub hostname2docroot {
  return "/var/docroots/$_[0]";
}

1;

Two comments and a question.  

First, in my little test, I alternate between five different hosts, and
don't do the cleanup handler to put the docroot back, and everything looks
fine.

Second, I couldn't get this

$r->document_root(hostname2docroot($r->hostname));

To set the docroot.  However, each of the following worked

my $new_docroot = hostname2docroot($r->hostname);
$r->document_root($new_docroot);

And 

$r->document_root("" . hostname2docroot($r->hostname));

And 

$r->document_root($_ = hostname2docroot($r->hostname));

How very strange.

My question is, why switch to apache2 if I have to use a prefork server, and
seemingly can't take advantage of threading?

Thanks,
Earl

> -----Original Message-----
> From: Geoffrey Young [mailto:geoff@xxxxxxxxxxxxxxx.xxx]
> Sent: Monday, February 14, 2005 4:27 PM
> To: Cahill, Earl
> Cc: mod_perl
> Subject: Re: $r->document_root
> 
> 
> 
> Geoffrey Young wrote:
> >>  $r->document_root(hostname2docroot($r->hostname));
> >
> >
> > you just can't do that without setting it back at the end of a request.
> see
> >
> >   http://www.webreference.com/programming/perl/cookbook/chap4/2.html
> >
> > for why.
> 
> I should add here that try doing this in a threaded environment (such as
> the
> worker mpm) and you're in for a world of trouble - if you need to do this
> with mp2 stick with prefork until we get the mutex stuff implemented (if
> ever).
> 
> --Geoff

(message missing)

$r->document_root
Cahill, Earl 23:14 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:21 on 14 Feb 2005

Re: $r->document_root
Geoffrey Young 23:26 on 14 Feb 2005

RE: $r->document_root
Cahill, Earl 20:43 on 15 Feb 2005

Re: $r->document_root
Geoffrey Young 21:10 on 15 Feb 2005

Re: $r->document_root
Stas Bekman 01:48 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 02:02 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 13:54 on 19 Feb 2005

Re: $r->document_root
Stas Bekman 17:21 on 19 Feb 2005

Re: $r->document_root
Joe Schaefer 14:12 on 19 Feb 2005

Re: $r->document_root
Geoffrey Young 05:26 on 20 Feb 2005

Re: $r->document_root
Stas Bekman 01:29 on 21 Feb 2005

Re: $r->document_root
Joe Schaefer 02:38 on 21 Feb 2005

Re: $r->document_root
Stas Bekman 02:43 on 21 Feb 2005

Generated at 12:48 on 22 Feb 2005 by mariachi v0.52