CGI-SpeedyCGI
view release on metacpan or search on metacpan
README.html view on Meta::CPAN
to
<P>
<PRE> #!/usr/bin/speedy
</PRE>
<P>
After the script is initially run, instead of exiting, the perl interpreter
is kept running. During subsequent runs, this interpreter is used to handle
new executions instead of starting a new perl interpreter each time. A very
fast frontend program, written in C, is executed for each request. This
fast frontend then contacts the persistent Perl process, which is usually
already running, to do the work and return the results.
<P>
By default each perl script runs in its own Unix process, so one perl
script can't interfere with another. Command line options can also be used
to deal with programs that have memory leaks or other problems that might
keep them from otherwise running persistently.
<P>
SpeedyCGI can be used to speed up perl CGI scripts. It conforms to the CGI
specification, and does not run perl code inside the web server. Since the
perl interpreter runs outside the web server, it can't cause problems for
the web server itself.
<P>
SpeedyCGI also provides an Apache module so that under the Apache web
server, scripts can be run without the overhead of doing a fork/exec for
each request. With this module a small amount of frontend code is run
within the web server - the perl interpreters still run outside the server.
<P>
SpeedyCGI and PersistentPerl are currently both names for the same code.
SpeedyCGI was the original name, but because people weren't sure what it
did, the name PersistentPerl was picked as an alias. At some point
SpeedyCGI will be replaced by PersistentPerl, or become a sub-class of
PersistentPerl to avoid always having two distributions.
<P>
<HR>
<H1><A NAME="OPTIONS">OPTIONS</A></H1>
<P>
<HR>
<H2><A NAME="Setting_Option_Values">Setting Option Values</A></H2>
<P>
SpeedyCGI options can be set in several ways:
<DL>
<DT><STRONG><A NAME="item_Command">Command Line</A></STRONG><DD>
<P>
The speedy command line is the same as for regular perl, with the exception
that SpeedyCGI specific options can be passed in after a ``--''.
<P>
For example the line:
<P>
<PRE> #!/usr/bin/speedy -w -- -t300
</PRE>
<P>
at the top of your script will set the perl option ``<CODE>-w</CODE>'' and will pass the ``<CODE>-t</CODE>'' option to SpeedyCGI, setting the Timeout value to 300 seconds.
</DL>
<DL>
<DT><STRONG><A NAME="item_Environment">Environment</A></STRONG><DD>
<P>
Environment variables can be used to pass in options. This can only be done
before the initial execution, not from within the script itself. The name
of the environment variable is always SPEEDY_ followed by the option name
in upper-case. For example to set the speedy Timeout option, use the
environment variable named SPEEDY_TIMEOUT.
</DL>
<DL>
<DT><STRONG><A NAME="item_Module">Module</A></STRONG><DD>
<P>
The CGI::SpeedyCGI module provides the setopt method to set options from
within the perl script at runtime. There is also a getopt method to
retrieve the current options. See <A HREF="#METHODS">METHODS</A> below.
</DL>
<DL>
<DT><STRONG><A NAME="item_Apache">Apache</A></STRONG><DD>
<P>
If you are using the optional Apache module, SpeedyCGI options can be set
in the <EM>httpd.conf</EM> file. The name of the apache directive will always be Speedy followed by
the option name. For example to set the Timeout option, use the apache
directive SpeedyTimeout.
</DL>
<P>
<HR>
<H2><A NAME="Context">Context</A></H2>
<P>
Not all options below are available in all contexts. The context for which
each option is valid is listed on the ``Context'' line in the section
below. There are three contexts:
<DL>
<DT><STRONG><A NAME="item_speedy">speedy</A></STRONG><DD>
<P>
The command-line ``speedy'' program, used normally with #! at the top of
your script or from a shell prompt.
</DL>
<DL>
<DT><STRONG><A NAME="item_mod_speedycgi">mod_speedycgi</A></STRONG><DD>
<P>
The optional Apache mod_speedycgi module.
</DL>
<DL>
<DT><STRONG><A NAME="item_module">module</A></STRONG><DD>
<P>
During perl execution via the CGI::SpeedyCGI module's getopt/setopt
methods.
</DL>
<P>
<HR>
<H2><A NAME="Options_Available">Options Available</A></H2>
<DL>
<DT><STRONG><A NAME="item_BackendProg">BackendProg</A></STRONG><DD>
<P>
<PRE> Command Line : -p<string>
Default Value : "/usr/bin/speedy_backend"
Context : mod_speedycgi, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Path to the speedy backend program.
</PRE>
<DT><STRONG><A NAME="item_BufsizGet">BufsizGet</A></STRONG><DD>
<P>
<PRE> Command Line : -B<number>
Default Value : 131072
Context : speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Use <number> bytes as the maximum size for the buffer that
receives data from the perl backend.
</PRE>
<DT><STRONG><A NAME="item_BufsizPost">BufsizPost</A></STRONG><DD>
README.html view on Meta::CPAN
<PRE> Command Line : -g<string>
Default Value : "none"
Context : mod_speedycgi, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Allow a single perl interpreter to run multiple scripts.
All scripts that are run with the same group name and by
the same user will be run by the same group of perl
interpreters. If the group name is "none" then grouping is
disabled and each interpreter will run one script.
Different group names allow scripts to be separated into
different groups. Name is case-sensitive, and only the
first 12-characters are significant. Specifying an empty
group name is the same as specifying the group name
"default" - this allows just specifying "-g" on the command
line to turn on grouping.
</PRE>
<DT><STRONG><A NAME="item_MaxBackends">MaxBackends</A></STRONG><DD>
<P>
<PRE> Command Line : -M<number>
Default Value : 0 (no max)
Context : mod_speedycgi, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> If non-zero, limits the number of speedy backends running
for this perl script to <number>.
</PRE>
<DT><STRONG><A NAME="item_MaxRuns">MaxRuns</A></STRONG><DD>
<P>
<PRE> Command Line : -r<number>
Default Value : 500
Context : mod_speedycgi, module, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Once the perl interpreter has run <number> times, re-exec
the backend process. Zero indicates no maximum. This
option is useful for processes that tend to consume
resources over time.
</PRE>
<DT><STRONG><A NAME="item_PerlArgs">PerlArgs</A></STRONG><DD>
<P>
<PRE> Command Line : N/A
Default Value : ""
Context : mod_speedycgi
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Command-line options to pass to the perl interpreter.
</PRE>
<DT><STRONG><A NAME="item_Timeout">Timeout</A></STRONG><DD>
<P>
<PRE> Command Line : -t<number>
Default Value : 3600 (one hour)
Context : mod_speedycgi, module, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> If no new requests have been received after <number>
seconds, exit the persistent perl interpreter. Zero
indicates no timeout.
</PRE>
<DT><STRONG><A NAME="item_TmpBase">TmpBase</A></STRONG><DD>
<P>
<PRE> Command Line : -T<string>
Default Value : "/tmp/speedy"
Context : mod_speedycgi, speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Use the given prefix for creating temporary files. This
must be a filename prefix, not a directory name.
</PRE>
<DT><STRONG><A NAME="item_Version">Version</A></STRONG><DD>
<P>
<PRE> Command Line : -v
Context : speedy
</PRE>
<P>
<PRE> Description:
</PRE>
<P>
<PRE> Print the SpeedyCGI version and exit.
</PRE>
</DL>
<P>
<HR>
<H1><A NAME="METHODS">METHODS</A></H1>
<P>
The following methods are available in the CGI::SpeedyCGI module.
<DL>
<DT><STRONG><A NAME="item_new">new</A></STRONG><DD>
<P>
Create a new CGI::SpeedyCGI object.
<P>
<PRE> my $sp = CGI::SpeedyCGI->new;
</PRE>
<DT><STRONG><A NAME="item_register_cleanup">register_cleanup($function_ref)</A></STRONG><DD>
<P>
Register a function that will be called at the end of each request, after
your script finishes running, but before STDOUT and STDERR are closed.
Multiple functions can be added by calling the method more than once. At
the end of the request, each function will be called in the order in which
it was registered.
<P>
<PRE> $sp->register_cleanup(\&cleanup_func);
</PRE>
<DT><STRONG><A NAME="item_add_shutdown_handler">add_shutdown_handler($function_ref)</A></STRONG><DD>
<P>
Add a function to the list of functions that will be called right before
the perl interpreter exits. This is <STRONG>not</STRONG> at the end of each request, it is when the perl interpreter decides to exit
completely due to a Timeout or reaching MaxRuns.
<P>
<PRE> $sp->add_shutdown_handler(sub {$dbh->logout});
</PRE>
<DT><STRONG><A NAME="item_set_shutdown_handler">set_shutdown_handler($function_ref)</A></STRONG><DD>
<P>
Deprecated. Similar to <A HREF="#item_add_shutdown_handler">add_shutdown_handler</A>, but only allows for a single function to be registered.
<P>
<PRE> $sp->set_shutdown_handler(sub {$dbh->logout});
</PRE>
<DT><STRONG><A NAME="item_i_am_speedy">i_am_speedy</A></STRONG><DD>
<P>
Returns a boolean telling whether this script is running under SpeedyCGI or
not. A perl script can run under regular perl, or under SpeedyCGI. This
method allows the script to tell which environment it is in.
<P>
<PRE> $sp->i_am_speedy;
</PRE>
<P>
To make your script as portable as possible, you can use the following test
to make sure both the SpeedyCGI module is available and you are running
under SpeedyCGI:
<P>
<PRE> if (eval {require CGI::SpeedyCGI} && CGI::SpeedyCGI->i_am_speedy) {
Do something SpeedyCGI specific here...
</PRE>
<P>
To increase the speed of this check you can also test whether the following
variable is defined instead of going through the object interface:
<P>
<PRE> $CGI::SpeedyCGI::i_am_speedy
</PRE>
<DT><STRONG><A NAME="item_setopt">setopt($optname, $value)</A></STRONG><DD>
<P>
Set one of the SpeedyCGI options given in <A HREF="#Options_Available">Options Available</A>. Returns the option's previous value. <CODE>$optname</CODE> is
case-insensitive.
<P>
<PRE> $sp->setopt('TIMEOUT', 300);
</PRE>
<DT><STRONG><A NAME="item_getopt">getopt($optname)</A></STRONG><DD>
<P>
Return the current value of one of the SpeedyCGI options.
<CODE>$optname</CODE> is case-insensitive.
<P>
<PRE> $sp->getopt('TIMEOUT');
</PRE>
<DT><STRONG><A NAME="item_shutdown_now">shutdown_now</A></STRONG><DD>
<P>
Shut down the perl interpreter right away. This function does not return.
<P>
<PRE> $sp->shutdown_now
</PRE>
<DT><STRONG><A NAME="item_shutdown_next_time">shutdown_next_time</A></STRONG><DD>
( run in 1.318 second using v1.01-cache-2.11-cpan-39bf76dae61 )