All,

I apologize if this has already been covered...I looked at the archives
since May but couldn't see anything covering this (there were related items
but their solutions didn't solve this problem).

Here an explanation of the problem:

We want to post experiment results to an "upload server" which is running
Apache HTTP Server (2.0.46) and mod_perl (1.99_09).  When we post a sequence
of files to the server, some of them are written to the local disk and some
are not.  That is, the test fails when using ModPerl::Registry but it
succeeds when using ModPerl::PerlRun.

In analyzing which ones work and which ones do not, I wrote a quick test to
see why the transfer is not working.  From the looks of the results, it
appears that the first request handled by a particular Apache process/thread
"works" and that any subsequent requests handled by that thread "fail."
Works means that the file in the test gets saved to disk and fail means that
a file of size "0" gets written to disk.

Below are the httpd.conf segments (working and failing), the test client
(test_client.pl) and the test server (test_server.pl which is accessible
from the /cpdn/cgi-bin location).

Any suggestions?  Thanks in advance...

Also, does it matter if I use ModPerl::PerlRun instead of ModPerl::Registry
(I have read some about this at
http://apache.perl.org/docs/2.0/api/ModPerl/Registry.html but the
documentation there is a little light).

--
Working httpd.conf
--
<Location /cpdn/cgi-bin>
      AllowOverride None
      SetHandler perl-script
      PerlResponseHandler ModPerl::PerlRun
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Allow from All
</Location>

--
Failing httpd.conf
--
<Location /cpdn/cgi-bin>
      AllowOverride None
      SetHandler perl-script
      PerlResponseHandler ModPerl::Registry
      PerlOptions +ParseHeaders
      Options +ExecCGI
      Allow from All
</Location>

--
test_client.pl
--
#!/usr/bin/perl
use strict;

use LWP::UserAgent;
use HTTP::Request::Common;

my $postUrl = $ARGV[0];
my $file = $ARGV[1];

my $postType = 'form-data';

my $ua = new LWP::UserAgent;
my $req = POST($postUrl,
               Content_Type => $postType,
               Content => [ file => ["$file"] ]);

my $res = $ua->request($req);
if ($res->is_success()) {
  print "POST test successful\n";
  print $res->content();
} else {
  print STDERR "POST test failed";
  print STDERR "code: " . $res->code() . "\n";
  print STDERR "message: " . $res->message() . "\n";
}

--
test_server.pl
--
use strict;
use CGI qw(:standard);

my $cgi = new CGI;
&saveFile();

sub saveFile {
  my $inputfile = $cgi->param('file');
  my $outputfile = "/tmp/file-" . $$ . "-" . time();
  open(FILE,">$outputfile") || printError();
  my $buffer;
  while (read($inputfile,$buffer,2096)) {
    print FILE $buffer;
  }
  close(FILE);
  undef $buffer;
}

sub printError {
  print header();
  print "Content-type: text/plain\n";
  print "Status: 500$\n";
  print "Message: Internal Error\n";
  exit;
}

Cheers
--
   Steve Bannerman
   [EMAIL PROTECTED]
   44.(0)1865.273866

Reply via email to