You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by jk jk <jk...@gmail.com> on 2007/09/21 22:23:00 UTC

Problem with RequestRec and Headers

I'm trying to port a preexisting CGI app to mod_perl2 and could use some
help.

Here goes a test case that should illustrate my problem:

The code pasted below loads the page properly the first time it's accessed.
However, upon multiple reloads in firefox, the headers either disappear
altogether or the page is downloaded in the download manager.  I assume this
is because the wrong $r object is being accessed by the request?  In any
case, I'm at a loss and would really appreciate some input.  Thanks in
advance.

---------------------------
---------------------------
File: tester.cgi
=============
#!/usr/bin/perl


use strict;
use lib qw(.....);

use testme::testmod;

my $r = shift;

my $object = testme::testmod->instance($r);
$object->printme();
1;


=============
File: testme/testmod.pm
=============

package testme::testmod;

use Apache2::RequestUtil;
use strict;

use base qw /Class::Singleton/;

sub printme{

    my ( $self, $args ) = @_;

    my $r = Apache2::RequestUtil->request;

    $self->{r}->content_type('text/html');

    print "A Page of Rendered HTML\n";
}

sub _new_instance{

    my ( $class, $r ) = @_;

    my $self = {};

    bless $self, $class;

    $self->{r} = $r;

    return ( $self );

}

1;

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
As a Registry script, it does get it.  I've made sure of that by using
Data::Dumper to take a look.

Thanks. --JAK

On 9/22/07, André Warnier <aw...@ice-sa.com> wrote:
>
> jk jk wrote:
> [..]
> >> my $r = shift;
>
> One of the brighter lights on this list correct me if I'm wrong, but I
> think there's some basic confusion here.
>
> This is a cgi-bin script, it is not an Apache/mod_perl module executed
> as a mod_perl handler.
> Thus it does not get a "request object" as argument.
> Thus I'm not quite sure what the result of the above statement is, but
> probably not what you expect.
>
>

Re: Problem with RequestRec and Headers

Posted by André Warnier <aw...@ice-sa.com>.
jk jk wrote:
[..]
>> my $r = shift;

One of the brighter lights on this list correct me if I'm wrong, but I 
think there's some basic confusion here.

This is a cgi-bin script, it is not an Apache/mod_perl module executed 
as a mod_perl handler.
Thus it does not get a "request object" as argument.
Thus I'm not quite sure what the result of the above statement is, but 
probably not what you expect.


Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
I should have also noted that I'm using ModPerl2, Apache2, It's running
under Registry, and keep-alive if off. Thanks again. --JAK

On 9/21/07, jk jk <jk...@gmail.com> wrote:
>
> I'm trying to port a preexisting CGI app to mod_perl2 and could use some
> help.
>
> Here goes a test case that should illustrate my problem:
>
> The code pasted below loads the page properly the first time it's
> accessed.  However, upon multiple reloads in firefox, the headers either
> disappear altogether or the page is downloaded in the download manager.  I
> assume this is because the wrong $r object is being accessed by the
> request?  In any case, I'm at a loss and would really appreciate some
> input.  Thanks in advance.
>
> ---------------------------
> ---------------------------
> File: tester.cgi
> =============
> #!/usr/bin/perl
>
>
> use strict;
> use lib qw(.....);
>
> use testme::testmod;
>
> my $r = shift;
>
> my $object = testme::testmod->instance($r);
> $object->printme();
> 1;
>
>
> =============
> File: testme/testmod.pm
> =============
>
> package testme::testmod;
>
> use Apache2::RequestUtil;
> use strict;
>
> use base qw /Class::Singleton/;
>
> sub printme{
>
>     my ( $self, $args ) = @_;
>
>     my $r = Apache2::RequestUtil->request;
>
>     $self->{r}->content_type('text/html');
>
>     print "A Page of Rendered HTML\n";
> }
>
> sub _new_instance{
>
>     my ( $class, $r ) = @_;
>
>     my $self = {};
>
>     bless $self, $class;
>
>     $self->{r} = $r;
>
>     return ( $self );
>
> }
>
> 1;
>
>
>
>

Re: Problem with RequestRec and Headers

Posted by Perrin Harkins <pe...@elem.com>.
On 9/23/07, jk jk <jk...@gmail.com> wrote:
> It was my impression that the most direct method of porting would be to use
> Class::Singleton (Apache::Singleton::Request).

It would be, but Apache::Singleton::Request is different from
Class::Singleton in that it stores the instance in $r->pnotes instead
of in a global variable.

Apache::Singleton::Request looks like it already has been ported to
mod_perl 2.  What was it that didn't work for you?  Do you have the
latest release?

- Perrin

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
I'm trying to port a pre-existing application built using a singleton
design.  Various class instances use a __PACKAGE__::getInstance() method to
get a handle on the current request's instance.  getInstance just returns
$self which is a global variable.  This works as a cgi, since every request
is in a separate interpreter.  It does not in mod_perl for obvious reasons.
It was my impression that the most direct method of porting would be to use
Class::Singleton (Apache::Singleton::Request).  Any other ideas?  Thanks.
--JAK

On 9/23/07, Perrin Harkins <pe...@elem.com> wrote:
>
> On 9/23/07, jk jk <jk...@gmail.com> wrote:
> > I've been trying to use Apache::Singleton::Request under the assumption
> that
> > you're right about Class::Singleton being the crux of the issue.
> > Unfortunately, I can't get it working under Apache2.  Is there a
> different
> > module for mp2/apache2 ?
>
> It should be easy to port if you want to.  I wonder why you're trying
> to use a singleton at all though.  It seems like either you should
> create a new object every time, or just use class methods if you don't
> need an object.  If this was just to get access to the request object,
> you don't need it.  You can always get the request object from
> anywhere using Apache2::RequestUtil.
>
> By the way, a quick look at Class::Singleton confirms what Philippe
> said: the instance() method just returns an existing instance after
> the first call and ignores all parameters.  It's not a mod_perl
> incomaptibilty; it's the intended behavior of the module.
>
> - Perrin
>

Re: Problem with RequestRec and Headers

Posted by Perrin Harkins <pe...@elem.com>.
On 9/23/07, jk jk <jk...@gmail.com> wrote:
> I've been trying to use Apache::Singleton::Request under the assumption that
> you're right about Class::Singleton being the crux of the issue.
> Unfortunately, I can't get it working under Apache2.  Is there a different
> module for mp2/apache2 ?

It should be easy to port if you want to.  I wonder why you're trying
to use a singleton at all though.  It seems like either you should
create a new object every time, or just use class methods if you don't
need an object.  If this was just to get access to the request object,
you don't need it.  You can always get the request object from
anywhere using Apache2::RequestUtil.

By the way, a quick look at Class::Singleton confirms what Philippe
said: the instance() method just returns an existing instance after
the first call and ignores all parameters.  It's not a mod_perl
incomaptibilty; it's the intended behavior of the module.

- Perrin

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
Ended up modifying his Apache::Singleton::Request module to work with my
app.  Was really just a matter of getting rid of the MP1 code and changing
the requestutils to requestrecs.  In any case, everything finally works ( I
think ).  Thanks for all the help.  I really appreciate it. --JAK

On 9/24/07, bharanee rathna <de...@gmail.com> wrote:
>
> Yep, that's a bug
>
> perldoc Apache2::RequestUtil
>
>   # get the global request object (requires PerlOptions +GlobalRequest)
>   $r = Apache2::RequestUtil->request;
>
> which means u need GlobalRequest in apache config, which I'm not a big fan
> of. Better raise a bug in cpan rt for this module and get Tatsuhiko to fix
> it. By the looks of it, this hasn't been updated in a while.
>
> personally I don't really see a need for Apache::Singleton::Process unless
> there needs to be a module for consistency in Apache:: namespace,
> class::singleton does pretty much the same job. If you need a per-request
> singleton meanwhile,  cookup something quickly of your own that uses apache
> pnotes to store the instance
>
> perldoc Apache2::RequestRec
>
>
>
> On 9/24/07, jk jk <jk...@gmail.com> wrote:
> >
> > I looked at the source.  It does seem to be written for both.  My
> > understanding was that everything for apache2 was supposed to be in the
> > Apach2:: namespace.  In any case I posted the install error below.  Does an
> > environment variable need to be set?
> >
> >
> > perl Makefile.PL
> > Warning: prerequisite mod_perl 0 not found.
> > Writing Makefile for Apache::Singleton
> >
> > If I install it anyway I get "[Sun Sep 23 15:09:49 2007] [error] Can't
> > locate Apache/RequestUtil.pm in @INC (@INC contains:......"
> >
> > Thanks. --JAK
> >
> > On 9/23/07, bharanee rathna < deepfryed@gmail.com> wrote:
> > >
> > > AFAIK Apache::Singleton works for MP2, also it does both per request
> > > and per process singletons.
> > >
> > >
> > > On 9/24/07, jk jk < jk.lists.questions@gmail.com> wrote:
> > > >
> > > > I've been trying to use Apache::Singleton::Request under the
> > > > assumption that you're right about Class::Singleton being the crux of the
> > > > issue.  Unfortunately, I can't get it working under Apache2.  Is there a
> > > > different module for mp2/apache2 ?  Thanks for your patience. --JAK
> > > >
> > > > On 9/23/07, jk jk <jk.lists.questions@gmail.com > wrote:
> > > > >
> > > > > Why is that?  Class::Singleton is modperl compatible,
> > > > > Apache::Singleton is the same thing with a few more features.  Its purpose
> > > > > to simplify singleton application creation.  My understanding was it would
> > > > > only allow a single instance of the object to be created for each request,
> > > > > not forever.  Please explain your reasoning.  Thanks. --JAK
> > > > >
> > > > > On 9/23/07, Philippe M. Chiasson < gozer@ectoplasm.org> wrote:
> > > > > >
> > > > > > jk jk wrote:
> > > > > > > I'm trying to port a preexisting CGI app to mod_perl2 and
> > > > > > could use some
> > > > > > > help.
> > > > > > >
> > > > > > > Here goes a test case that should illustrate my problem:
> > > > > > >
> > > > > > > The code pasted below loads the page properly the first time
> > > > > > it's
> > > > > > > accessed.  However, upon multiple reloads in firefox, the
> > > > > > headers either
> > > > > > > disappear altogether or the page is downloaded in the download
> > > > > > manager.
> > > > > > > I assume this is because the wrong $r object is being accessed
> > > > > > by the
> > > > > > > request?  In any case, I'm at a loss and would really
> > > > > > appreciate some
> > > > > > > input.  Thanks in advance.
> > > > > > > [...]
> > > > > > >
> > > > > > > =============
> > > > > > > File: testme/testmod.pm
> > > > > > > =============
> > > > > > >
> > > > > > > package testme::testmod;
> > > > > > >
> > > > > > > use Apache2::RequestUtil;
> > > > > > > use strict;
> > > > > > >
> > > > > > > use base qw /Class::Singleton/;
> > > > > >
> > > > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > > >
> > > > > > From the documentation of Class::Singleton:
> > > > > >
> > > > > > # this only gets called the first time instance() is called
> > > > > >
> > > > > > > sub _new_instance{
> > > > > > >
> > > > > > >     my ( $class, $r ) = @_;
> > > > > > >
> > > > > > >     my $self = {};
> > > > > > >
> > > > > > >     bless $self, $class;
> > > > > > >
> > > > > > >     $self->{r} = $r;
> > > > > > >
> > > > > > >     return ( $self );
> > > > > > >
> > > > > > > }
> > > > > >
> > > > > > So effectively, your code will capture the $r (once for each
> > > > > > child)
> > > > > > from the first request and keep it forever. Trying to use it for
> > > > > > subsequent
> > > > > > requests will cause the kind of problems you've seen.
> > > > > >
> > > > > >
> > > > > > ------------------------------------------------------------------------
> > > > > > Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107
> > > > > > 88C3A5A5
> > > > > > http://gozer.ectoplasm.org/
> > > > > > m/gozer\@(apache|cpan|ectoplasm)\.org/
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: Problem with RequestRec and Headers

Posted by bharanee rathna <de...@gmail.com>.
Yep, that's a bug

perldoc Apache2::RequestUtil

  # get the global request object (requires PerlOptions +GlobalRequest)
  $r = Apache2::RequestUtil->request;

which means u need GlobalRequest in apache config, which I'm not a big fan
of. Better raise a bug in cpan rt for this module and get Tatsuhiko to fix
it. By the looks of it, this hasn't been updated in a while.

personally I don't really see a need for Apache::Singleton::Process unless
there needs to be a module for consistency in Apache:: namespace,
class::singleton does pretty much the same job. If you need a per-request
singleton meanwhile,  cookup something quickly of your own that uses apache
pnotes to store the instance

perldoc Apache2::RequestRec



On 9/24/07, jk jk <jk...@gmail.com> wrote:
>
> I looked at the source.  It does seem to be written for both.  My
> understanding was that everything for apache2 was supposed to be in the
> Apach2:: namespace.  In any case I posted the install error below.  Does an
> environment variable need to be set?
>
>
> perl Makefile.PL
> Warning: prerequisite mod_perl 0 not found.
> Writing Makefile for Apache::Singleton
>
> If I install it anyway I get "[Sun Sep 23 15:09:49 2007] [error] Can't
> locate Apache/RequestUtil.pm in @INC (@INC contains:......"
>
> Thanks. --JAK
>
> On 9/23/07, bharanee rathna <de...@gmail.com> wrote:
> >
> > AFAIK Apache::Singleton works for MP2, also it does both per request and
> > per process singletons.
> >
> >
> > On 9/24/07, jk jk < jk.lists.questions@gmail.com> wrote:
> > >
> > > I've been trying to use Apache::Singleton::Request under the
> > > assumption that you're right about Class::Singleton being the crux of the
> > > issue.  Unfortunately, I can't get it working under Apache2.  Is there a
> > > different module for mp2/apache2 ?  Thanks for your patience. --JAK
> > >
> > > On 9/23/07, jk jk <jk.lists.questions@gmail.com > wrote:
> > > >
> > > > Why is that?  Class::Singleton is modperl compatible,
> > > > Apache::Singleton is the same thing with a few more features.  Its purpose
> > > > to simplify singleton application creation.  My understanding was it would
> > > > only allow a single instance of the object to be created for each request,
> > > > not forever.  Please explain your reasoning.  Thanks. --JAK
> > > >
> > > > On 9/23/07, Philippe M. Chiasson < gozer@ectoplasm.org> wrote:
> > > > >
> > > > > jk jk wrote:
> > > > > > I'm trying to port a preexisting CGI app to mod_perl2 and could
> > > > > use some
> > > > > > help.
> > > > > >
> > > > > > Here goes a test case that should illustrate my problem:
> > > > > >
> > > > > > The code pasted below loads the page properly the first time
> > > > > it's
> > > > > > accessed.  However, upon multiple reloads in firefox, the
> > > > > headers either
> > > > > > disappear altogether or the page is downloaded in the download
> > > > > manager.
> > > > > > I assume this is because the wrong $r object is being accessed
> > > > > by the
> > > > > > request?  In any case, I'm at a loss and would really appreciate
> > > > > some
> > > > > > input.  Thanks in advance.
> > > > > > [...]
> > > > > >
> > > > > > =============
> > > > > > File: testme/testmod.pm
> > > > > > =============
> > > > > >
> > > > > > package testme::testmod;
> > > > > >
> > > > > > use Apache2::RequestUtil;
> > > > > > use strict;
> > > > > >
> > > > > > use base qw /Class::Singleton/;
> > > > >
> > > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > > >
> > > > > From the documentation of Class::Singleton:
> > > > >
> > > > > # this only gets called the first time instance() is called
> > > > >
> > > > > > sub _new_instance{
> > > > > >
> > > > > >     my ( $class, $r ) = @_;
> > > > > >
> > > > > >     my $self = {};
> > > > > >
> > > > > >     bless $self, $class;
> > > > > >
> > > > > >     $self->{r} = $r;
> > > > > >
> > > > > >     return ( $self );
> > > > > >
> > > > > > }
> > > > >
> > > > > So effectively, your code will capture the $r (once for each
> > > > > child)
> > > > > from the first request and keep it forever. Trying to use it for
> > > > > subsequent
> > > > > requests will cause the kind of problems you've seen.
> > > > >
> > > > >
> > > > > ------------------------------------------------------------------------
> > > > > Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107
> > > > > 88C3A5A5
> > > > > http://gozer.ectoplasm.org/
> > > > > m/gozer\@(apache|cpan|ectoplasm)\.org/
> > > > >
> > > > >
> > > > >
> > > >
> > >
> >
>

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
I looked at the source.  It does seem to be written for both.  My
understanding was that everything for apache2 was supposed to be in the
Apach2:: namespace.  In any case I posted the install error below.  Does an
environment variable need to be set?


perl Makefile.PL
Warning: prerequisite mod_perl 0 not found.
Writing Makefile for Apache::Singleton

If I install it anyway I get "[Sun Sep 23 15:09:49 2007] [error] Can't
locate Apache/RequestUtil.pm in @INC (@INC contains:......"

Thanks. --JAK

On 9/23/07, bharanee rathna <de...@gmail.com> wrote:
>
> AFAIK Apache::Singleton works for MP2, also it does both per request and
> per process singletons.
>
>
> On 9/24/07, jk jk < jk.lists.questions@gmail.com> wrote:
> >
> > I've been trying to use Apache::Singleton::Request under the assumption
> > that you're right about Class::Singleton being the crux of the issue.
> > Unfortunately, I can't get it working under Apache2.  Is there a different
> > module for mp2/apache2 ?  Thanks for your patience. --JAK
> >
> > On 9/23/07, jk jk <jk.lists.questions@gmail.com > wrote:
> > >
> > > Why is that?  Class::Singleton is modperl compatible,
> > > Apache::Singleton is the same thing with a few more features.  Its purpose
> > > to simplify singleton application creation.  My understanding was it would
> > > only allow a single instance of the object to be created for each request,
> > > not forever.  Please explain your reasoning.  Thanks. --JAK
> > >
> > > On 9/23/07, Philippe M. Chiasson < gozer@ectoplasm.org> wrote:
> > > >
> > > > jk jk wrote:
> > > > > I'm trying to port a preexisting CGI app to mod_perl2 and could
> > > > use some
> > > > > help.
> > > > >
> > > > > Here goes a test case that should illustrate my problem:
> > > > >
> > > > > The code pasted below loads the page properly the first time it's
> > > > > accessed.  However, upon multiple reloads in firefox, the headers
> > > > either
> > > > > disappear altogether or the page is downloaded in the download
> > > > manager.
> > > > > I assume this is because the wrong $r object is being accessed by
> > > > the
> > > > > request?  In any case, I'm at a loss and would really appreciate
> > > > some
> > > > > input.  Thanks in advance.
> > > > > [...]
> > > > >
> > > > > =============
> > > > > File: testme/testmod.pm
> > > > > =============
> > > > >
> > > > > package testme::testmod;
> > > > >
> > > > > use Apache2::RequestUtil;
> > > > > use strict;
> > > > >
> > > > > use base qw /Class::Singleton/;
> > > >
> > > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > > >
> > > > From the documentation of Class::Singleton:
> > > >
> > > > # this only gets called the first time instance() is called
> > > >
> > > > > sub _new_instance{
> > > > >
> > > > >     my ( $class, $r ) = @_;
> > > > >
> > > > >     my $self = {};
> > > > >
> > > > >     bless $self, $class;
> > > > >
> > > > >     $self->{r} = $r;
> > > > >
> > > > >     return ( $self );
> > > > >
> > > > > }
> > > >
> > > > So effectively, your code will capture the $r (once for each child)
> > > > from the first request and keep it forever. Trying to use it for
> > > > subsequent
> > > > requests will cause the kind of problems you've seen.
> > > >
> > > >
> > > > ------------------------------------------------------------------------
> > > > Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107
> > > > 88C3A5A5
> > > > http://gozer.ectoplasm.org/
> > > > m/gozer\@(apache|cpan|ectoplasm)\.org/
> > > >
> > > >
> > > >
> > >
> >
>

Re: Problem with RequestRec and Headers

Posted by bharanee rathna <de...@gmail.com>.
AFAIK Apache::Singleton works for MP2, also it does both per request and per
process singletons.


On 9/24/07, jk jk <jk...@gmail.com> wrote:
>
> I've been trying to use Apache::Singleton::Request under the assumption
> that you're right about Class::Singleton being the crux of the issue.
> Unfortunately, I can't get it working under Apache2.  Is there a different
> module for mp2/apache2 ?  Thanks for your patience. --JAK
>
> On 9/23/07, jk jk <jk...@gmail.com> wrote:
> >
> > Why is that?  Class::Singleton is modperl compatible, Apache::Singleton
> > is the same thing with a few more features.  Its purpose to simplify
> > singleton application creation.  My understanding was it would only allow a
> > single instance of the object to be created for each request, not forever.
> > Please explain your reasoning.  Thanks. --JAK
> >
> > On 9/23/07, Philippe M. Chiasson < gozer@ectoplasm.org> wrote:
> > >
> > > jk jk wrote:
> > > > I'm trying to port a preexisting CGI app to mod_perl2 and could use
> > > some
> > > > help.
> > > >
> > > > Here goes a test case that should illustrate my problem:
> > > >
> > > > The code pasted below loads the page properly the first time it's
> > > > accessed.  However, upon multiple reloads in firefox, the headers
> > > either
> > > > disappear altogether or the page is downloaded in the download
> > > manager.
> > > > I assume this is because the wrong $r object is being accessed by
> > > the
> > > > request?  In any case, I'm at a loss and would really appreciate
> > > some
> > > > input.  Thanks in advance.
> > > > [...]
> > > >
> > > > =============
> > > > File: testme/testmod.pm
> > > > =============
> > > >
> > > > package testme::testmod;
> > > >
> > > > use Apache2::RequestUtil;
> > > > use strict;
> > > >
> > > > use base qw /Class::Singleton/;
> > >
> > > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > >
> > > From the documentation of Class::Singleton:
> > >
> > > # this only gets called the first time instance() is called
> > >
> > > > sub _new_instance{
> > > >
> > > >     my ( $class, $r ) = @_;
> > > >
> > > >     my $self = {};
> > > >
> > > >     bless $self, $class;
> > > >
> > > >     $self->{r} = $r;
> > > >
> > > >     return ( $self );
> > > >
> > > > }
> > >
> > > So effectively, your code will capture the $r (once for each child)
> > > from the first request and keep it forever. Trying to use it for
> > > subsequent
> > > requests will cause the kind of problems you've seen.
> > >
> > >
> > > ------------------------------------------------------------------------
> > > Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107
> > > 88C3A5A5
> > > http://gozer.ectoplasm.org/
> > > m/gozer\@(apache|cpan|ectoplasm)\.org/
> > >
> > >
> > >
> >
>

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
I've been trying to use Apache::Singleton::Request under the assumption that
you're right about Class::Singleton being the crux of the issue.
Unfortunately, I can't get it working under Apache2.  Is there a different
module for mp2/apache2 ?  Thanks for your patience. --JAK

On 9/23/07, jk jk <jk...@gmail.com> wrote:
>
> Why is that?  Class::Singleton is modperl compatible, Apache::Singleton is
> the same thing with a few more features.  Its purpose to simplify singleton
> application creation.  My understanding was it would only allow a single
> instance of the object to be created for each request, not forever.  Please
> explain your reasoning.  Thanks. --JAK
>
> On 9/23/07, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
> >
> > jk jk wrote:
> > > I'm trying to port a preexisting CGI app to mod_perl2 and could use
> > some
> > > help.
> > >
> > > Here goes a test case that should illustrate my problem:
> > >
> > > The code pasted below loads the page properly the first time it's
> > > accessed.  However, upon multiple reloads in firefox, the headers
> > either
> > > disappear altogether or the page is downloaded in the download
> > manager.
> > > I assume this is because the wrong $r object is being accessed by the
> > > request?  In any case, I'm at a loss and would really appreciate some
> > > input.  Thanks in advance.
> > > [...]
> > >
> > > =============
> > > File: testme/testmod.pm
> > > =============
> > >
> > > package testme::testmod;
> > >
> > > use Apache2::RequestUtil;
> > > use strict;
> > >
> > > use base qw /Class::Singleton/;
> >
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> >
> > From the documentation of Class::Singleton:
> >
> > # this only gets called the first time instance() is called
> >
> > > sub _new_instance{
> > >
> > >     my ( $class, $r ) = @_;
> > >
> > >     my $self = {};
> > >
> > >     bless $self, $class;
> > >
> > >     $self->{r} = $r;
> > >
> > >     return ( $self );
> > >
> > > }
> >
> > So effectively, your code will capture the $r (once for each child)
> > from the first request and keep it forever. Trying to use it for
> > subsequent
> > requests will cause the kind of problems you've seen.
> >
> > ------------------------------------------------------------------------
> > Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
> > http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/
> >
> >
> >
>

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
Why is that?  Class::Singleton is modperl compatible, Apache::Singleton is
the same thing with a few more features.  Its purpose to simplify singleton
application creation.  My understanding was it would only allow a single
instance of the object to be created for each request, not forever.  Please
explain your reasoning.  Thanks. --JAK

On 9/23/07, Philippe M. Chiasson <go...@ectoplasm.org> wrote:
>
> jk jk wrote:
> > I'm trying to port a preexisting CGI app to mod_perl2 and could use some
> > help.
> >
> > Here goes a test case that should illustrate my problem:
> >
> > The code pasted below loads the page properly the first time it's
> > accessed.  However, upon multiple reloads in firefox, the headers either
> > disappear altogether or the page is downloaded in the download manager.
> > I assume this is because the wrong $r object is being accessed by the
> > request?  In any case, I'm at a loss and would really appreciate some
> > input.  Thanks in advance.
> > [...]
> >
> > =============
> > File: testme/testmod.pm
> > =============
> >
> > package testme::testmod;
> >
> > use Apache2::RequestUtil;
> > use strict;
> >
> > use base qw /Class::Singleton/;
>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>
> From the documentation of Class::Singleton:
>
> # this only gets called the first time instance() is called
>
> > sub _new_instance{
> >
> >     my ( $class, $r ) = @_;
> >
> >     my $self = {};
> >
> >     bless $self, $class;
> >
> >     $self->{r} = $r;
> >
> >     return ( $self );
> >
> > }
>
> So effectively, your code will capture the $r (once for each child)
> from the first request and keep it forever. Trying to use it for
> subsequent
> requests will cause the kind of problems you've seen.
>
> ------------------------------------------------------------------------
> Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
> http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/
>
>
>

Re: Problem with RequestRec and Headers

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
jk jk wrote:
> I'm trying to port a preexisting CGI app to mod_perl2 and could use some
> help.
> 
> Here goes a test case that should illustrate my problem:
> 
> The code pasted below loads the page properly the first time it's
> accessed.  However, upon multiple reloads in firefox, the headers either
> disappear altogether or the page is downloaded in the download manager. 
> I assume this is because the wrong $r object is being accessed by the
> request?  In any case, I'm at a loss and would really appreciate some
> input.  Thanks in advance.
> [...]
> 
> =============
> File: testme/testmod.pm
> =============
> 
> package testme::testmod;
> 
> use Apache2::RequestUtil;
> use strict;
> 
> use base qw /Class::Singleton/;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

From the documentation of Class::Singleton:

# this only gets called the first time instance() is called

> sub _new_instance{
> 
>     my ( $class, $r ) = @_;
> 
>     my $self = {};
> 
>     bless $self, $class;
> 
>     $self->{r} = $r;
> 
>     return ( $self );
> 
> }

So effectively, your code will capture the $r (once for each child)
from the first request and keep it forever. Trying to use it for subsequent
requests will cause the kind of problems you've seen.

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/


Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
I spoke too soon.  While the header issue appears to be resolved, a new one
has surfaced.  The first 20 or so reloads (the number of spare servers?) are
ok, but after that nothing loads in the browser and the error pasted below
appears in the error_log.  Any ideas?  Thanks. --JAK

Re: Problem with RequestRec and Headers

Posted by jk jk <jk...@gmail.com>.
Welp, changing over to ModPerl::RegistryPrefork did the trick.  Thanks for
the advice.  I really appreciate it. --JAK


On 9/22/07, jk jk <jk...@gmail.com> wrote:
>
> My question would then be, in which situation would I be using an old one
> on a later request?  I suspect this may be the case, since the problem goes
> away if I turn keep-alive on. Thanks. --JAK
>
> On 9/22/07, Perrin Harkins <pe...@elem.com> wrote:
> >
> > On 9/21/07, jk jk <jk...@gmail.com> wrote:
> > > sub printme{
> > >
> > >     my ( $self, $args ) = @_;
> > >
> > >     my $r = Apache2::RequestUtil->request;
> > >
> > >     $self->{r}->content_type('text/html');
> > >
> > >     print "A Page of Rendered HTML\n";
> > > }
> >
> > You ask for $r from Apache2::RequestUtil here, but then you don't use
> > it.  That looks a bit odd, although not necessarily dangerous.  And
> > are you using the prefork MPM?
> >
> > In general, you don't want to put something like a Apache2::RequestRec
> > in a global that will not be gone at the end of the request.  It could
> > cause a lot of trouble if you tried to use an old one on a later
> > request.
> >
> > - Perrin
> >
>
>

Re: Problem with RequestRec and Headers

Posted by Perrin Harkins <pe...@elem.com>.
On 9/21/07, jk jk <jk...@gmail.com> wrote:
> sub printme{
>
>     my ( $self, $args ) = @_;
>
>     my $r = Apache2::RequestUtil->request;
>
>     $self->{r}->content_type('text/html');
>
>     print "A Page of Rendered HTML\n";
> }

You ask for $r from Apache2::RequestUtil here, but then you don't use
it.  That looks a bit odd, although not necessarily dangerous.  And
are you using the prefork MPM?

In general, you don't want to put something like a Apache2::RequestRec
in a global that will not be gone at the end of the request.  It could
cause a lot of trouble if you tried to use an old one on a later
request.

- Perrin