1

I am using the default install of Apache and mod_perl on Ubuntu 16.04.1 LTS, I also have reproduced this with the default JSON::XS and I updated to the latest from CPAN JSON-XS-3.02.

The code below works in all cases if I am not using mod_perl.

The script and html below work when using perl via mod_cgi with both POST and GET requests.

If however I am using mod_perl and I use a POST (as in the html provided) it fails, "Hello" does not print, and I get the following error in my apache log file.

Usage: JSON::XS::new(klass).

If I pass the same parameter(s) via a GET method, the script works fine.

test2.pl

#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use JSON::XS;

my $q = new CGI();
print $q->header(-type => 'text/plain');
my $action = $q->param('a');
my $json_str = '{"foo":"bar"}';
my $pscalar = JSON::XS->new->utf8->decode($json_str);
print "Hello";
exit 1;

HTML to call the above (named test2.pl on the server)

<html>
<body>
<form action="test2.pl" method="POST">
<input type="text" name="a"/>
<button type="submit">
</form>
</body>
</html>
Severun
  • 2,893
  • 1
  • 16
  • 22

1 Answers1

0

OK So this was a rather wild goose chase, analyzing apache core dumps and stack traces, fixing bugs that weren't really there... Long story short.

I was trying to add an include directory to my perl by using

PerlSwitches -I/usr/local/lib/site_perl/my_new_directory

As part of that I added

PerlOptions +Parent so that I would get a new interpreter for each virtual host so my -I was effective for only one virtual host at a time.

I had added those flags before I enabled mod_perl, so when I enabled mod_perl, it just never worked.

By removing the PerlOptions +Parent things started working as expected.

As a side note, it appears +Parent makes things wonky in genral.

Severun
  • 2,893
  • 1
  • 16
  • 22
  • Some more info on this. In order to use +Parent you must be using the mpm_worker mod which runs Apache multi-threaded. When using mpm_worker, the +Parent worked, but then I got random hangs on requests when the server started to load up (not much load, like 10 or 20 simultaneous connections) The solution I ended up going with is running multiple Apache instances with the mpm_prefork module, then adding my PerlSwitches -I to the global apache2.conf – Severun Aug 24 '16 at 23:17