You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Joshua Ferraro <jm...@liblime.com> on 2005/09/06 20:35:09 UTC

mod_perl for Koha Library System

Hi all,

I'm in the process of testing Koha (http://koha.org) with mod_perl
and I'm running into a couple of snags. I get the following errors 
in the logs:

[Tue Sep 06 13:42:09 2005] [error] [client 192.168.2.111] malformed header from script. Bad header=22994: circulation.pl, referer: /cgi-bin/koha/circ/circulation.pl
[Tue Sep 06 13:42:09 2005] [warn] /cgi-bin/koha/circ/circulation.pl did not send an HTTP header

The result is that '22994' is printed at the top-left of the
circulation page. Also, I've noticed that several flags/statuses
aren't updated when mod_perl is enabled. I'm not sure if this
is a related problem or not.

I was helped by phred on IRC who pointed me to the assbackwards
method: http://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#C_assbackwards_

However, It's unclear to me how to implement this in Koha (or even if
I'm headed in the right direction). Every script in Koha calls
output_html_with_http_headers which takes three arguments:
($query, $cookie, $html). Here's a link to the module that contains
that sub:
http://cvs.sourceforge.net/viewcvs.py/koha/koha/C4/Interface/CGI/Output.pm?rev=1.2&view=markup

Anyone have any suggestion for how to troubleshoot this?

Thanks,
-- 
Joshua Ferraro               VENDOR SERVICES FOR OPEN-SOURCE SOFTWARE
President, Technology       migration, training, maintenance, support
LibLime                                Featuring Koha Open-Source ILS
jmf@liblime.com |Full Demos at http://liblime.com/koha |1(888)KohaILS

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Joshua Ferraro wrote:
> Yep I read the link. However, I think the only code I'll
> need to change will be the mod_perl_startup.pl that I
> call from my conf file (as well as some lines in the
> conf file) as I didn't really add any mod_perl specific
> code to Koha. Does this sound right?
Very possibly yes.

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Joshua Ferraro <jm...@liblime.com>.
On Tue, Sep 06, 2005 at 03:43:55PM -0400, Philip M. Gollucci wrote:
> Probably, You did read that link right, you'll have to modify code when you 
> update.
Yep I read the link. However, I think the only code I'll
need to change will be the mod_perl_startup.pl that I
call from my conf file (as well as some lines in the
conf file) as I didn't really add any mod_perl specific
code to Koha. Does this sound right?

Thanks,
-- 
Joshua Ferraro               VENDOR SERVICES FOR OPEN-SOURCE SOFTWARE
President, Technology       migration, training, maintenance, support
LibLime                                Featuring Koha Open-Source ILS
jmf@liblime.com |Full Demos at http://liblime.com/koha |1(888)KohaILS

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Joshua Ferraro wrote:
> Hmm ... unfortunately this won't work as there's a whole
> authentication framework to get past ... any other
> suggestions? ;-)
You might try LWP or just looking through the code.

> my OS package management system reports that I'm
> running mod_perl 1.99_16-3 (running Fedora Core
> 3). What's the best way to run a newer version of
> mod_perl under Fedora Core 3? Should I install
> from source?
Probably, You did read that link right, you'll have to modify code when you update.


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Geoffrey Young <ge...@modperlcookbook.org>.
and 3.07 is the most recent that handles the
>> latest mod_perl API changes.
> 
> Since when, ... I thought it was 3.08 and some other stuff was fixed in
> 3.10.

oops :)

> 
> Also, 3.11 is out :)

which is why I was a bit lazy about checking my versions :0

--Geoff

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Geoffrey Young wrote:
> 
> Philip M. Gollucci wrote:
> 
>>>this feels like the start of a chunked response.  something is awry
>>>with the
>>>buffering in the response... or somesuch IIRC :)
>>
>>For reference the relevant code is: $query is a CGI.pm object
> 
> 
> ah!  make sure that CGI.pm is a recent version, then - versions less than
> 3.0 had buffering problems and 3.07 is the most recent that handles the
> latest mod_perl API changes.
Since when, ... I thought it was 3.08 and some other stuff was fixed in 3.10.

Also, 3.11 is out :)


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Philip M. Gollucci wrote:
>> this feels like the start of a chunked response.  something is awry
>> with the
>> buffering in the response... or somesuch IIRC :)
> 
> For reference the relevant code is: $query is a CGI.pm object

ah!  make sure that CGI.pm is a recent version, then - versions less than
3.0 had buffering problems and 3.07 is the most recent that handles the
latest mod_perl API changes.

does anyone know offhand if older CGI.pm's blow up with mp 2.0 or if it just
ignores it?  I can't recall...

--Geoff

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> this feels like the start of a chunked response.  something is awry with the
> buffering in the response... or somesuch IIRC :)
For reference the relevant code is: $query is a CGI.pm object

sub guesscharset ($) {
     my($html) = @_;
     my $charset = undef;
     local($`, $&, $', $1, $2, $3);
     # FIXME... These regular expressions will miss a lot of valid tags!
     if ($html =~ 
/<meta\s+http-equiv=(["']?)Content-Type\1\s+content=(["'])text\/html\s*;\s*charset=([^\2\s\r\n]+)\2\s*(?:\/?)>/is) {
         $charset = $3;
     } elsif ($html =~ 
/<meta\s+content=(["'])text\/html\s*;\s*charset=([^\1\s\r\n]+)\1\s+http-equiv=(["']?)Content-Type\3\s*(?:\/?)>/is) {
         $charset = $2;
     }
     return $charset;
} # guess

sub guesstype ($) {
     my($html) = @_;
     my $charset = guesscharset($html);
     return defined $charset? "text/html; charset=$charset": "text/html";
}

=item output_html_with_http_headers

    &output_html_with_http_headers($query, $cookie, $html)

Outputs the HTML page $html with the appropriate HTTP headers,
with the authentication cookie $cookie and a Content-Type that
corresponds to the HTML page $html.

=cut

sub output_html_with_http_headers ($$$) {
     my($query, $cookie, $html) = @_;
     print $query->header(
     -type   => guesstype($html),
     -cookie => $cookie,
     ), $html;
}

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Geoffrey Young <ge...@modperlcookbook.org>.

Joshua Ferraro wrote:
> Perrin et al,
> 
> Thanks for the help thusfar. I upgraded MP2 to 2.0.1 from source.
> I'm still getting the same problems with statuses not working
> and header errors. Here's a snip from the log:
> 

> [Tue Sep 06 17:10:34 2005] [error] [client 192.168.2.59] malformed header from script. Bad header=40069TYPE html PUBLIC "-//W3C/

this feels like the start of a chunked response.  something is awry with the
buffering in the response... or somesuch IIRC :)

I'd toggle the value of ParseHeaders on and off, play around with
GlobalRequest, and whatnot to see if the port of koha to mp2 didn't make use
of some specific features of mp2 that are more mp1-legacy-type features.

I saw on google that you asked someone on the koha forum for his httpd.conf
specific from a working mp2 installation.  I'd push harder for that -
nothing is as helpful as configuration known to work :)

also, perrin suggested live headers.  if you can't use telnet to query the
server that's the next best thing :)

--Geoff

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Joshua Ferraro wrote:
> I'll hunt down Geoff's emails and check the headers again, though I
> suspect that the problem is Koha-related rather than a problem with
> mod_perl.
If thats indeed the problem, you could always add
print "Content-Type: text/html\n\n";

near the top of that cgi.

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Joshua Ferraro <jm...@liblime.com>.
Perrin et al,

Thanks for the help thusfar. I upgraded MP2 to 2.0.1 from source.
I'm still getting the same problems with statuses not working
and header errors. Here's a snip from the log:

[Tue Sep 06 17:10:12 2005] [error] [client 192.168.2.59] malformed header from script. Bad header=40069: circulation.pl, referer: /cgi-bin/koha/circ/circulation.pl
[Tue Sep 06 17:10:12 2005] [warn] /cgi-bin/koha/circ/circulation.pl did not send an HTTP header
[Tue Sep 06 17:10:34 2005] [error] [client 192.168.2.59] malformed header from script. Bad header=40069TYPE html PUBLIC "-//W3C/: circulation.pl, referer: /cgi-bin/koha/circ/circulation.pl
[Tue Sep 06 17:10:34 2005] [warn] /cgi-bin/koha/circ/circulation.pl did not send an HTTP header

I'll hunt down Geoff's emails and check the headers again, though I
suspect that the problem is Koha-related rather than a problem with
mod_perl.

Thanks,

--
Joshua Ferraro               VENDOR SERVICES FOR OPEN-SOURCE SOFTWARE
President, Technology       migration, training, maintenance, support
LibLime                                Featuring Koha Open-Source ILS
jmf@liblime.com |Full Demos at http://liblime.com/koha |1(888)KohaILS

Re: mod_perl for Koha Library System

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2005-09-06 at 12:40 -0700, Joshua Ferraro wrote:
> > GET /path HTTP/1.0\n\n
> > And look
> Hmm ... unfortunately this won't work as there's a whole
> authentication framework to get past ...

Unless you're using SSL, it will work fine.  You'd have to learn what to
type in though.  It's easier to use GET (a tool that comes with LWP), or
lynx with --dump-headers.  There's also a Firefox plugin that will show
the headers.

Your problem sounds like an issue I recall others having with numbers
showing up in the middle of requests when using HTTP 1.1.  I think using
the latest mod_perl may fix it, but you might like to look in the mail
archives too.  I believe Geoff Young was the one who identified the
problem last time.

- Perrin


Re: mod_perl for Koha Library System

Posted by Joshua Ferraro <jm...@liblime.com>.
On Tue, Sep 06, 2005 at 03:09:21PM -0400, Philip M. Gollucci wrote:
> Joshua Ferraro wrote:
> >turned on already. How do I check if a header's getting sent 
> The easiest is just telnet localhost 80
> GET /path HTTP/1.0\n\n
> And look
Hmm ... unfortunately this won't work as there's a whole
authentication framework to get past ... any other
suggestions? ;-)

> >use Apache2 ();
> Ew... your mp2 is way old.  You should update,
my OS package management system reports that I'm
running mod_perl 1.99_16-3 (running Fedora Core
3). What's the best way to run a newer version of
mod_perl under Fedora Core 3? Should I install
from source?

Thanks,

-- 
Joshua Ferraro               VENDOR SERVICES FOR OPEN-SOURCE SOFTWARE
President, Technology       migration, training, maintenance, support
LibLime                                Featuring Koha Open-Source ILS
jmf@liblime.com |Full Demos at http://liblime.com/koha |1(888)KohaILS

Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Joshua Ferraro wrote:
> turned on already. How do I check if a header's getting sent 
The easiest is just telnet localhost 80
GET /path HTTP/1.0\n\n
And look

> use Apache2 ();
Ew... your mp2 is way old.  You should update,

http://perl.apache.org/docs/2.0/rename.html

-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com


Re: mod_perl for Koha Library System

Posted by Joshua Ferraro <jm...@liblime.com>.
Hi Philip,

Thanks for the speedy response. I belive I've got +ParseHeaders
turned on already. How do I check if a header's getting sent (note
that the log message complains that one isn't:
[Tue Sep 06 14:51:59 2005] [error] [client 192.168.3.50] malformed header from script. Bad header=31583: circulation.pl, referer: /cgi-bin/koha/circ/circulation.pl
[Tue Sep 06 14:51:59 2005] [warn] /cgi-bin/koha/circ/circulation.pl did not send an HTTP header

Here's the relevant lines from my apache .conf files (both in 
conf.d dir):

koha-httpd.conf :
...snip...
   <Location /cgi-bin/koha/>
        # mod_perl mode
        SetHandler perl-script
        PerlResponseHandler ModPerl::Registry
        PerlOptions +ParseHeaders
        Options +ExecCGI
   </Location>
...snip...

------
perl.conf :

LoadModule perl_module modules/mod_perl.so
PerlWarn On
PerlRequire "/build/mod_perl/mod_perl-startup.pl"

-------
/build/mod_perl/mod_perl-startup.pl looks like this:

if ( ! {MOD_PERL}) { die "GATEWAY_INTERFACE not Perl!"; }

# see also: http://perl.apache.org/docs/2.0/user/porting/compat.html

use Apache2 ();

# use lib qw(/srv/www/perl-lib);
use lib qw(/build/koha/ /usr/lib/perl5/5.8.3 );

# enable if the mod_perl 1.0 compatibility is needed
use Apache::compat ();

use ModPerl::Util (); #for CORE::GLOBAL::exit

use Apache::RequestRec ();
use Apache::RequestIO ();
use Apache::RequestUtil ();

use Apache::ServerRec ();
use Apache::ServerUtil ();
use Apache::Connection ();
use Apache::Log ();

use APR::Table ();

use ModPerl::Registry ();

use Apache::Const -compile => ':common';
use APR::Const -compile => ':common';

1;


Re: mod_perl for Koha Library System

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> [Tue Sep 06 13:42:09 2005] [error] [client 192.168.2.111] malformed header from script. Bad header=22994: circulation.pl, referer: /cgi-bin/koha/circ/circulation.pl
> [Tue Sep 06 13:42:09 2005] [warn] /cgi-bin/koha/circ/circulation.pl did not send an HTTP header
I assume this is running under ModPerl::Registry or similiar.

I believe you'll want to add
http://perl.apache.org/docs/2.0/user/porting/compat.html#C_PerlSendHeader_
aka
<Location /cgi-bin>
   ...
   PerlOptions +ParseHeaders
</Location>

Also, be sure that a header _IS_ getting sent.


-- 
END
------------------------------------------------------------
     What doesn't kill us can only make us stronger.
                 Nothing is impossible.
				
Philip M. Gollucci (pgollucci@p6m7g8.com) 301.254.5198
Consultant / http://p6m7g8.net/Resume/
Senior Developer / Liquidity Services, Inc.
   http://www.liquidityservicesinc.com
        http://www.liquidation.com
        http://www.uksurplus.com
        http://www.govliquidation.com
        http://www.gowholesale.com