Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

HTML::Template::Pro - Issue with template files larger than 8K

by Uniden (Initiate)
on Jul 08, 2014 at 16:11 UTC ( [id://1092752]=perlquestion: print w/replies, xml ) Need Help??

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

My web server setup is: FreeBSD 10.0, Apache 2.4, Perl 5.16, HTML::Template::Pro 0.9510

After years of successfully using HTML::Template::Pro with FreeBSD 6.2, Apache 2.2 and Perl 5.x, I've recently moved everything to the stack named in the first line. Right after moving the Perl scripts over, I have noticed that some scripts did trigger following error in httpd:

[Tue Jul 08 09:37:26.169883 2014] [cgid:error] [pid 49924] [client x.x.x.x:59214] malformed header from script 'test.pl': Bad header: <!doctype html>

First of all, all my scripts use HTML::Template::Pro. I tried this and that, thinking that the error is somewhere in the Perl scripts, but couldn't find the cause of the error. Then I saw that scripts calling smaller templates don't crash, while larger templates would trigger the above error. Then I simplified to the bone and created following Perl script 'test.pl':

#!/usr/bin/perl use strict; use HTML::Template::Pro; my $tmpl = HTML::Template::Pro -> new(filename => 'test.tmpl'); print "Content-Type: text/html\n\n"; $tmpl -> output();
..and the template 'test.tmpl':
<!doctype html> <html> <body> <p>blah blah</p> </body> </html>

I ran test.pl and everything was fine, no error. Then I started adding a lot of blah blahs until the size of the template file size hit exactly 8,192 bytes, at which time it crashed with a 500 and with the above error logged in the httpd-error.log. If I delete a single character from the template file so it goes below 8K, the script runs again. I have absolutely no idea why this happens. By the way, large html files do not crash Apache, nor do Perl scripts printing html code directly (without HTML::Template::Pro. I tried both to the extreme, creating MBs of html code and wasn't able to crash anything at all.

I am not aware of any settings that I could change for HTML::Template::Pro. If anyone has an idea what I could do to prevent this from happening, I am all in for experiments.

Replies are listed 'Best First'.
Re: HTML::Template::Pro - Issue with template files larger than 8K
by InfiniteSilence (Curate) on Jul 08, 2014 at 18:42 UTC

    Doesn't happen to me (Perl v5.10.0; OpenSuse 11.0/Apache 2.2.19; HTML-Template-Pro-0.9510):

    #!/usr/bin/perl use strict; use HTML::Template::Pro; my $tmpl = HTML::Template::Pro->new(filename=>'/tmp/blah.html'); print qq|Content-Type: text/html\n\n|; print $tmpl->output(); 1;

    Snippet of the file:

    <!DOCTYPE html> <span>blah</span><span>blah</span><span>blah</span><span>blah</span><s +pan>blah</spa\ n><span>blah</span><span>blah</span><span>blah</span><span>blah</span> +<span>blah</s\ pan><span>blah</span><span>blah</span><span>blah</span><span>blah</spa +n><span>blah<\ /span><span>blah</span><span>blah</span><span>blah</span>...

    File size is:

    170017

    Has to be something specific to your setup. Does it work when you run it on the command line?

    Celebrate Intellectual Diversity

      Yep, thanks, I totally forgot to run from command line. Well, from command line it works just fine.. I upped the size of the template file to about 5MB and no issues with command line. Is that weird or what?!? So I suspect that the issue is rather at the Apache level. I guess I will just reset my httpd.conf and start from there.

        Oki Doki! The culprit is the output buffering. When executing the script via command line, the header does display exactly after 8192 bytes, which when run through Apache produces an error. Output buffering can be disabled in Perl, so I added the line "$|=1;" to my script and now it works.

        #!/usr/bin/perl
        use strict;
        $|=1;
        use HTML::Template::Pro;
        my $tmpl = HTML::Template::Pro -> new(filename => 'test.tmpl');
        print "Content-Type: text/html\n\n";
        $tmpl -> output();
Re: HTML::Template::Pro - Issue with template files larger than 8K
by Anonymous Monk on Jul 08, 2014 at 18:32 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1092752]
Approved by boftx
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-03-29 04:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found