FAQ
I had a typo on my previous post -- below has been corrected:
--------------------------


I have 2 virtuals configured for the same server: FOO and BAR:

One has directive:
PerlSetVar BAR /www/bar/bar_file

The other has:
PerlSetVar FOO /www/foo/foo_file

When I run (/www/bar/bar_scripts/test.cgi):

package mypackage;
my($myvar)=();
my $r=Apache2::RequestUtil->request;
$myvar=$r->dir_config('BAR');

$myvar is "/www/bar/bar_file" ... which is what I'd expect.

....But when I later run (/www/foo/foo_scripts/test.cgi):

package mypackage;
my($myvar)=();
my $r=Apache2::RequestUtil->request;
$myvar=$r->dir_config('FOO');

$myvar may be "/www/foo/foo_file" or more likely "".

Worse, if I try to run the /www/bar_scripts/test.cgi again, $myvar may now
be "".

What's going on here? Why are these these conflicting??

This has been very troublesome over the past many hours

Cycling the server only fixes the problem until more than one of the scripts
is run.

Thanks for enlightenment.. in advance.

WF

Search Discussions

  • Philip M. Gollucci at Sep 23, 2006 at 9:54 am

    Will Fould wrote:
    package mypackage;
    my($myvar)=();
    my $r=Apache2::RequestUtil->request;
    $myvar=$r->dir_config('BAR');
    From what I can see, you're only issue is that you've duplicated
    package mypackage;

    make that

    package X; # for vhost1 and script1
    package Y; # for vhosts2 and script2

    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => 1
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => NOT DEFINED
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => 2
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => NOT DEFINED
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => 2
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => NOT DEFINED
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => 1

    Source Code:
    http://test.p6m7g8.net/TEST/PerlSetVar.pm

    Virtual Host Configs:
    http://test.p6m7g8.net/TEST/net.p6m7g8.net.test.v1.conf
    http://test.p6m7g8.net/TEST/net.p6m7g8.net.test.v2.conf


    --
    ------------------------------------------------------------------------
    Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
    Consultant / http://p6m7g8.net/Resume/resume.shtml
    Senior Software Engineer - TicketMaster - http://ticketmaster.com
    1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F

    When I call your name, Girl, it starts to flame
    Burning in my heart, Tearing it all apart..
    No matter how I try My love I cannot hide....
  • Will Fould at Sep 23, 2006 at 3:41 pm
    Thank Philip -- That helps! But both virtual hosts run their own
    installation of the same scripts (hence, same package names). The
    installation loads it's configuration for those scripts located at $myvar (a
    simple package with variables). Until recently, installations were always on
    separate servers.

    I thought that packages loaded from different locations, (but with the same
    name), would not conflict. Silly me.

    Is there a better way to do what I'm trying to do without running separate
    servers for each host?

    Thanks a lot for your reply and all your work on MP.


    W

    On 9/23/06, Philip M. Gollucci wrote:

    Will Fould wrote:
    package mypackage;
    my($myvar)=();
    my $r=Apache2::RequestUtil->request;
    $myvar=$r->dir_config('BAR');
    From what I can see, you're only issue is that you've duplicated
    package mypackage;

    make that

    package X; # for vhost1 and script1
    package Y; # for vhosts2 and script2

    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => 1
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => NOT DEFINED
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => 2
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => NOT DEFINED
    $ GET "http://v2.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => 2
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v2"
    v2 => NOT DEFINED
    $ GET "http://v1.test.p6m7g8.net/perlsetvar?cv=v1"
    v1 => 1

    Source Code:
    http://test.p6m7g8.net/TEST/PerlSetVar.pm

    Virtual Host Configs:
    http://test.p6m7g8.net/TEST/net.p6m7g8.net.test.v1.conf
    http://test.p6m7g8.net/TEST/net.p6m7g8.net.test.v2.conf


    --
    ------------------------------------------------------------------------
    Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
    Consultant / http://p6m7g8.net/Resume/resume.shtml
    Senior Software Engineer - TicketMaster - http://ticketmaster.com
    1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F

    When I call your name, Girl, it starts to flame
    Burning in my heart, Tearing it all apart..
    No matter how I try My love I cannot hide....
  • Michael Peters at Sep 23, 2006 at 4:40 pm

    Will Fould wrote:

    I thought that packages loaded from different locations, (but with the
    same name), would not conflict. Silly me.
    This is because even though you've told apache to map a certain URL to a certain
    script, there is only 1 running Perl interpreter. And since Perl only allows 1
    file to occupy a certain namespace you get those conflicts.
    Is there a better way to do what I'm trying to do without running
    separate servers for each host?
    The only way to have 2 different packages use the same package name is to have
    separate Perls with different @INCS running. There's no way to do this under
    Apache/mod_perl (that I'm aware of). So either run 2 different Apaches, or put
    the modules into their own namespaces. Instead of "package Foo" do "package
    ClientA::Foo".

    --
    Michael Peters
    Developer
    Plus Three, LP
  • Malcolm J Harwood at Sep 23, 2006 at 5:12 pm

    On Saturday 23 September 2006 11:41, Will Fould wrote:

    Thank Philip -- That helps! But both virtual hosts run their own
    installation of the same scripts (hence, same package names). The
    installation loads it's configuration for those scripts located at $myvar
    (a simple package with variables). Until recently, installations were
    always on separate servers.

    I thought that packages loaded from different locations, (but with the same
    name), would not conflict. Silly me.

    Is there a better way to do what I'm trying to do without running separate
    servers for each host?
    Actually looking at your original question, it looks like it should work as
    long as you are calling $r->dir_config('FOO') on each request. Doing it as a
    global within the module wont work (you'll just get whatever the first access
    gives you).

    I do almost the same thing with a small server I run - the db access
    parameters are in the config file (local security isn't an issue) and the
    application pulls the correct accessors depending on which virtual host is
    accessed.
  • Philip M. Gollucci at Sep 23, 2006 at 10:42 pm

    Will Fould wrote:
    Thank Philip -- That helps! But both virtual hosts run their own
    installation of the same scripts (hence, same package names). The
    installation loads it's configuration for those scripts located at
    $myvar (a simple package with variables). Until recently, installations
    were always on separate servers.
    Apparently you didn't notice, that I was sharing the /www/sites/net/p6m7g8/test/lib dir across
    both v1 and v2. Not only that I was using the IDENTICAL file for the package to serve both.
    :)

    Pull your code into functions within the package.
    I thought that packages loaded from different locations, (but with the
    same name), would not conflict. Silly me.
    Well, the $INC{file1} = '/path1' and $INC{file2} = '/path2'

    --
    ------------------------------------------------------------------------
    Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
    Consultant / http://p6m7g8.net/Resume/resume.shtml
    Senior Software Engineer - TicketMaster - http://ticketmaster.com
    1024D/A79997FA F357 0FDD 2301 6296 690F 6A47 D55A 7172 A799 97F

    When I call your name, Girl, it starts to flame
    Burning in my heart, Tearing it all apart..
    No matter how I try My love I cannot hide....

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmodperl @
categoriesmodperl, perl
postedSep 23, '06 at 8:18a
activeSep 23, '06 at 10:42p
posts6
users4
websiteperl.apache.org

People

Translate

site design / logo © 2021 Grokbase