You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Dan Horne <da...@redbone.co.nz> on 2005/05/09 06:19:29 UTC

Can't retrieve page I just created with LWP under mod_perl

I've written a small CGI::Application CMS that publishes content to flat
files via. The file-type can be any that the designers decide, but generally
it will be something that supports includes such as SSI or PHP. This is fine
most of the time but occasionally I need to produce dynamic pages - e.g. a
search result. 

To do this, I generate the search result php/shtml page to the file system,
and then request it from the web server using LWP:

    my $file = $self->get_value('cms_document_root') . "/" . $page;
    $self->logger->debug("Creating $file");
    
    # write the results to the temporary file
    open(FH, ">$file") || die "Cannot create $file";
    print FH $template->output();
    close FH || die "Cannot close $file";    
    $self->logger->debug("Created $file");
    
    # request the temporary file 
    my $request_page = "http://" . $ENV{SERVER_NAME} .
        $self->get_value('cms_publish_url') . "/$page";
    $self->logger->debug("request_page: $request_page");
    my $agent        = LWP::UserAgent->new;
    my $request      = HTTP::Request->new(GET => $request_page);

This works fine under standard CGI, but the LWP request times out under
mod_perl. The temporary page name is random, so I know that it's not a file
conflict.

Have I missed something? I'm using Apache 1.3.31 and mod_perl 1.29 on
Windows XP, but whatever I do has to also work under vanilla CGI.

regards

Dan Horne



RE: Can't retrieve page I just created with LWP under mod_perl

Posted by Dan Horne <da...@redbone.co.nz>.
> 
> It might be that, on Windows, you're running into the 
> multithreading limitations of mod_perl 1: 
> http://perl.apache.org/docs/1.0/os/win32/multithread.html

Thanks, Randy - I had a nagging thought that I had read about a
single-threading issue, so I scoured the Apache docs, but to no avail ...
that's because I should have checked the mod_perl docs!

> fails for me under mod_perl 1 on Win32, but works fine
> with mod_perl 2. Do you have the option to upgrade your
> Windows system to use mod_perl 2/Apache 2?
> 

Not this time, but maybe next time.

Thanks

Dan



RE: Can't retrieve page I just created with LWP under mod_perl

Posted by Randy Kobes <ra...@theoryx5.uwinnipeg.ca>.
On Tue, 10 May 2005, Dan Horne wrote:

> > > > This works fine under standard CGI, but the LWP
> > > > request times out under mod_perl. The temporary page
> > > > name is random, so I know that it's not a file
> > > > conflict.
> > > >
> > > > Have I missed something? I'm using Apache 1.3.31 and
> > > > mod_perl 1.29 on Windows XP, but whatever I do has
> > > > to also work under vanilla CGI.
>
> Ok, I've determined that it works fine under Linux,
> mod_perl and Apache 1.3.33, so I assume that it's a
> problem with Windows. That's a shame, because I typically
> develop on Windows, but I guess that since I'm deploying
> to Linux, I can live with things

It might be that, on Windows, you're running into the
multithreading limitations of mod_perl 1:
http://perl.apache.org/docs/1.0/os/win32/multithread.html
which means that one request must finish before another
one can be handled. For example, this mod_perl registry
script:
=====================================================
use strict;
use warnings;
use LWP;
use File::Spec;
my $htdocs = 'D:/Apache2/htdocs';
my $file = 'log.txt';
my $abs_file = File::Spec->catfile($htdocs, $file);
open(my $fh, '>', $abs_file) or die "Cannot open $abs_file: $!";
print $fh "This is a test";
close $fh;
my $request_page = 'http://' . $ENV{SERVER_NAME} . "/$file";
my $agent = LWP::UserAgent->new;
my $request = HTTP::Request->new(GET => $request_page);
my $response = $agent->request($request);
print "Content-type: text/plain\n\n";
if ($response->is_success) {
  print "Received content of " . $response->content;
}
else {
  print "Something went wrong ...";
}
============================================================
fails for me under mod_perl 1 on Win32, but works fine
with mod_perl 2. Do you have the option to upgrade your
Windows system to use mod_perl 2/Apache 2?

-- 
best regards,
randy kobes

RE: Can't retrieve page I just created with LWP under mod_perl

Posted by Dan Horne <da...@redbone.co.nz>.
> > > This works fine under standard CGI, but the LWP request times out 
> > > under mod_perl. The temporary page name is random, so I know that 
> > > it's not a
> > file
> > > conflict.
> > >
> > > Have I missed something? I'm using Apache 1.3.31 and 
> mod_perl 1.29 
> > > on Windows XP, but whatever I do has to also work under 
> vanilla CGI.

Ok, I've determined that it works fine under Linux, mod_perl and Apache
1.3.33, so I assume that it's a problem with Windows. That's a shame,
because I typically develop on Windows, but I guess that since I'm deploying
to Linux, I can live with things

Dan



RE: Can't retrieve page I just created with LWP under mod_perl

Posted by Dan Horne <da...@redbone.co.nz>.
> -----Original Message-----
> From: Stas Bekman [mailto:stas@stason.org]
> Sent: Tuesday, 10 May 2005 1:39 a.m.
> To: dan.horne@redbone.co.nz
> Cc: modperl@perl.apache.org
> Subject: Re: Can't retrieve page I just created with LWP under mod_perl
> 
> Dan Horne wrote:
> > I've written a small CGI::Application CMS that publishes content to flat
> > files via. The file-type can be any that the designers decide, but
> generally
> > it will be something that supports includes such as SSI or PHP. This is
> fine
> > most of the time but occasionally I need to produce dynamic pages - e.g.
> a
> > search result.
> >
> > To do this, I generate the search result php/shtml page to the file
> system,
> > and then request it from the web server using LWP:
> >
> >     my $file = $self->get_value('cms_document_root') . "/" . $page;
> >     $self->logger->debug("Creating $file");
> >
> >     # write the results to the temporary file
> >     open(FH, ">$file") || die "Cannot create $file";
> >     print FH $template->output();
> >     close FH || die "Cannot close $file";
> >     $self->logger->debug("Created $file");
> >
> >     # request the temporary file
> >     my $request_page = "http://" . $ENV{SERVER_NAME} .
> >         $self->get_value('cms_publish_url') . "/$page";
> >     $self->logger->debug("request_page: $request_page");
> >     my $agent        = LWP::UserAgent->new;
> >     my $request      = HTTP::Request->new(GET => $request_page);
> >
> > This works fine under standard CGI, but the LWP request times out under
> > mod_perl. The temporary page name is random, so I know that it's not a
> file
> > conflict.
> >
> > Have I missed something? I'm using Apache 1.3.31 and mod_perl 1.29 on
> > Windows XP, but whatever I do has to also work under vanilla CGI.
> 
> Not sure if there is something specific under win32, but mod_perl differs
> from mod_cgi since:
> 
> 1) it is running under the same username the server runs with
> 2) the environment persists
> 
> In the script above, you don't use LWP, you create an agent, but you don't
> use it. I can't see where the actual request is.
> 
Sorry - the request is on the next line - missed it when I pasted the code:

my $response = $agent->request($request);

Assuming caveats one and two above, can anyone see anything obviously wrong?
The temp file gets created - I can see it on the file system. I'm guessing
it's due to the Win32 envronment.

Dan



Re: Can't retrieve page I just created with LWP under mod_perl

Posted by Stas Bekman <st...@stason.org>.
Dan Horne wrote:
> I've written a small CGI::Application CMS that publishes content to flat
> files via. The file-type can be any that the designers decide, but generally
> it will be something that supports includes such as SSI or PHP. This is fine
> most of the time but occasionally I need to produce dynamic pages - e.g. a
> search result. 
> 
> To do this, I generate the search result php/shtml page to the file system,
> and then request it from the web server using LWP:
> 
>     my $file = $self->get_value('cms_document_root') . "/" . $page;
>     $self->logger->debug("Creating $file");
>     
>     # write the results to the temporary file
>     open(FH, ">$file") || die "Cannot create $file";
>     print FH $template->output();
>     close FH || die "Cannot close $file";    
>     $self->logger->debug("Created $file");
>     
>     # request the temporary file 
>     my $request_page = "http://" . $ENV{SERVER_NAME} .
>         $self->get_value('cms_publish_url') . "/$page";
>     $self->logger->debug("request_page: $request_page");
>     my $agent        = LWP::UserAgent->new;
>     my $request      = HTTP::Request->new(GET => $request_page);
> 
> This works fine under standard CGI, but the LWP request times out under
> mod_perl. The temporary page name is random, so I know that it's not a file
> conflict.
> 
> Have I missed something? I'm using Apache 1.3.31 and mod_perl 1.29 on
> Windows XP, but whatever I do has to also work under vanilla CGI.

Not sure if there is something specific under win32, but mod_perl differs 
from mod_cgi since:

1) it is running under the same username the server runs with
2) the environment persists

In the script above, you don't use LWP, you create an agent, but you don't 
use it. I can't see where the actual request is.

-- 
__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com