I have a 'medium'
traffic e-commerce site (about 30GB xfer a month). It is mostly written in
Perl (about 40 scripts or 4,000 lines of code). We have had no problems with
performance to date but in preparation for future growth (in addition to other
changes to the site's scripts) I thought it would be a good idea to switch from
CGI to Mod_Perl.
I read all of Stas
Bekman's Porting Guidelines and looked at my scripts. While
I have a long programming history, I must admit I started cranking out the
code (in a nice modular fashion) as soon as I grasped the basic of the
language, ignoring things like the -w operator, use strict;, and only used
variable localization (my) in some of my subroutines. I have
determined that as a result, I would have quite a bit of work to do to move to
modPerl (using Apache::Registry) including:
- avoid inner
subrouting nesting problem by having all Perl scripts called by the webserver
only executive code in included files (using require from a main
script)
- make all variables
localized using 'my' and special variables using local (although my coding
is sloppy from a localization standpoint, it is written so it doesn't even need
global variables - all variables are passed through the subroutines properly
even though I forgot to specifically localize them)
- Make sure required
files are reloaded after modification by setting PerlInitHandler to Reload,
Setting PerlSetVar ReloadAll Off, and then when I am developing including
Apacher::Reload in the scripts I am working on, then taking it out when they go
into production (this was the method that made the most sense to
me.)
- I actually didn't
really understand the problem with testing from the shell and using CGI::Switch
or CGI.pm
- Use '^T = time' in
the scripts that I test filetime to determine its age
- Use 'open my $fh,
$filename or die $!; wherever I open files to insure they get closed
properly
That's going
to be A LOT of work and I have lots of other modifications to do. So then
I get to his section titled 'Apache::PerlRun--a closer look' and come to find
out that Apache:PerlRun is basically a nice compromise offering some (not all)
of the performance benefits of mod_Perl while not forcing you to have to
drastically clean up your code.
So here is my
strategy that I would like a sanity check from anyone on. Go through and
quickly clean up my existing code by adding use strict and localizing all
my variables (with 'my' and 'local' for special variables) and then run is under
mod_Perl using the Apache::PerlRun. Write all my new code so that it will
run under Apache::Registry and then when I have spare time (ya right) go work on
porting the older code.
On thing that
is interesting is that even though I added the -w operator to the end of
#!/usr/bin/perl in my scripts and added use stricts; I am not seeing the
hundreds of error messages I should see in either error_log or suexec_log.
Any ideas? Thanks.