I recently installed Apache 2.0.48 and mod_perl 1.99.xx. I immediately went into producing small snippets to test out the mod_perl environment. Just as fast, I've come across certain issues I hope I can have addressed. They follow below.

One of the first things I wondered is how far a person can go in respect to loading everything into memory and executing as little code as possible on each server hit. First thing I did was throw a PerlModule Apache::DBI line into httpd.conf to pool database connections. Second, I tried a simple script that loads CGI::Simple and prints a simple document. I then tried one with file io and discovered a "glitch" I don't like. The following script introduces most of my questions:

#!c:/perl/bin/perl -w $|++; use strict; use Cwd; our $q; BEGIN { require CGI::Simple; $q = CGI::Simple->new; } print $q->header('text/plain'), "We're in ", cwd();

First question I have: will the $|++; carry over to each repeated request? Will output buffering be disabled upon each server hit? Second of all, note the way I initialized the CGI::Simple object. I don't think I gain anything by loading the module within a BEGIN block; a module is only compiled once, so a simple use CGI::Simple; at the top of the script should be just as good right? I keep the same object alive throughout the life of the interpreter. Will CGI::Simple DWIM and be safe to use in such a manner? Or should I revert to creating a new query object on each hit? It works with this simple script, but will it become fubar'ed in certain situations? Next comes the "glitch" with the cwd. Even though the script is c:/apache2/www/port80/serve, it is run from c:/apache2. Besides doing a chdir "c:/apache2/www/port80/serve"; at the top of each script, is there an easier way to fix this? Perhaps a directive within httpd.conf or perl.conf to do a chdir itself before executing the script?

Another question: If I start up apache/mod_perl, run one of the scripts, edit that script's source and then run it again, I see that apache notes the modified timestamp on the file and recompiles the script. My question is whether the older source is expunged from memory or if it is kept around even though it won't be used again.

Yet another question: As far as I've heard, ModPerl::Registry overrides perl's core exit() function, so that the interpreter is not actually exited. Is it still safe to use exit() as a "stop executing code here" way of thinking? How about die()? When die() is called, will the interpreter exit? Is it safe to use $SIG{__DIE__} to catch the errors to a logfile?

Hope to hear some good answers to these questions. If anyone has more information about common mod_perl pitfalls and/or links to good FAQs, please share!


In reply to Knowing what works with mod_perl by Coruscate

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.