O'Reilly logo

Writing Apache Modules with Perl and C by Lincoln Stein, Doug MacEachern

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A.2. The Apache::PerlRun Class

The Apache::PerlRun handler is intended for Perl CGI scripts that depend strongly on the traditional one-process-per-execution CGI model and cannot deal with being invoked repeatedly in the same process. For example, a script that depends on a lot of global variables being uninitialized when it starts up is unlikely to work properly under Apache::Registry.

Like Apache::Registry, Apache::PerlRun manages a directory of CGI scripts, launching them when they are requested. However, unlike Apache::Registry, this module does not cache compiled scripts between runs. A script is loaded and compiled freshly each time it is requested. However, Apache::PerlRun still avoids the overhead of starting a new Perl interpreter for each CGI script, so it's faster than traditional Perl CGI scripting but slower than Apache::Registry or vanilla Apache API modules. It offers a possible upgrade path for CGI scripts: move the script to Apache::PerlRun initially to get a modest performance bump. This gives you time to rework the script to make it globally clean so that it can run under Apache::Registry for the full performance benefit.

The configuration section for running Apache::PerlRun is similar to Apache::Registry :

Alias /perl-run/ /home/www/perl-run/
<Location /perl>
  SetHandler     perl-script
  PerlHandler    Apache::PerlRun
  Options        +ExecCGI
  # optional
  PerlSendHeader On
</Location>

The Apache::PerlRun handler is only a small part of the picture. The rest of the Apache::PerlRun ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required