stuartc has asked for the wisdom of the Perl Monks concerning the following question:

This seems to be someting to do with the interaction between mod_perl and perl 5.6, but is really confusing me.

I have a server running perl 5.00503, apache 1.3.19 and mod_perl 1.25 where the code below works perfectly. Then I have my home/dev box which is running perl 5.6.1-26.72.3 and (now) apache 1.3.19/mod_perl 1.25 (configs basically the same except perl) where the same code will not work correctly under mod_perl.

If I run it as a standard cgi or from the shell it works. Under mod_perl the other program just gets a large (infinite?) amount of nothingness (as in $string = <FH> always returns an undef string)

The question is, why? Is it a bug in my code, mod_perl, perl or what? Is there a workaround or some better code to do the same thing?

The code in question:

package Local::JDS::Test; use strict; use Data::Dumper; use Apache::Constants; use IPC::Open2; use Local::JDS::Code; sub handler { my $r = shift; my %hash = call_plugin (); $r->content_type ('text/plain'); $r->send_http_header; $r->print (Dumper (\%hash)); return OK; } sub cgi_handler { my %hash = call_plugin (); print "Content-type: text/plain\n\n"; print Dumper (\%hash); } sub call_plugin { my $command = 'domain_get_expiry'; my %hash = (Domain => 'breadrecipe.com'); #$SIG{'CHLD'} = 'IGNORE'; my $pid = open2 (\*READ, \*WRITE, '/usr/local/apache/htdocs/jds/ba +ckend/plugins/srs_plugin.pl'); my $tmp = select (WRITE); $| = 1; select ($tmp); my $read = \*READ; my $write = \*WRITE; Local::JDS::Code::encode ($write, $command, %hash); my ($ok, %out) = Local::JDS::Code::decode ($read); print $write "QUIT\n\n"; close $write; close $read; return %out; } 1;
The test cgi (non mod_perl) code is just
#!/usr/bin/perl -w use strict; use Local::JDS::Test; Local::JDS::Test::cgi_handler ();
Local::JDS::Code just sends and receives text via the specified filehandle.

Replies are listed 'Best First'.
Re: Is this me or mod_perl?
by trs80 (Priest) on Apr 17, 2002 at 22:24 UTC
Re: Is this me or mod_perl?
by perrin (Chancellor) on Apr 17, 2002 at 20:41 UTC
    It's probably an error with permissions. Remember, mod_perl processes typically run as user "nobody." Try putting in some debug statements to see where things start to go differently when running under mod_perl.
      The CGI version works find (also running as nobody).

      The code thinks it sent stuff (ie warns just above the prints produce the correct output) but the other process does not get the data (but does in the cgi or run from shell cases).

        Warns above which print?