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.

In reply to Is this me or mod_perl? by stuartc

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.