#!/usr/local/bin/speedy
### Your CGI Script Here
## ## Optionally, use the CGI::SpeedyCGI module for various things ##
# Create a SpeedyCGI object use CGI::SpeedyCGI; my $sp = CGI::SpeedyCGI->new;
# See if we are running under SpeedyCGI or not. print "Running under speedy=", $sp->i_am_speedy ? 'yes' : 'no', "\n";
# Set up a shutdown handler $sp->set_shutdown_handler(sub { do something here });
# Set/get some SpeedyCGI options $sp->setopt('timeout', 30); print "maxruns=", $sp->getopt('maxruns'), "\n";
#!/usr/local/bin/perl
to
#!/usr/local/bin/speedy
After the script is initially run, instead of exiting, SpeedyCGI keeps the perl interpreter running in memory. During subsequent runs, this interpreter is used to handle new requests, instead of starting a new perl interpreter for each execution.
SpeedyCGI conforms to the CGI specification, and does not work inside the web server. A very fast cgi-bin (written in C) is executed for each request. This fast cgi-bin then contacts the persistent Perl process, which is usually already in memory, to do the work and return the results.
Since all of these processes run outside the web server, they can't cause problems for the web server itself. Also, each perl program runs as its own Unix process, so one program 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.
For example:
#!/usr/local/bin/speedy -w -- -t300
at the top of your script will call SpeedyCGI with the perl option ``-w
'' and will pass the ``-t
'' option to speedy, telling it to exit if no new requests have been
received after 300 seconds.
Command Line : -tN Environment : SPEEDY_TIMEOUT CGI::SpeedyCGI : TIMEOUT mod_speedycgi : SpeedyTimeout Default Value : 3600 (one hour)
Description:
If no new requests have been received after N seconds, exit the persistent perl interpreter. Use 0 to indicate no timeout.
Command Line : -rN Environment : SPEEDY_MAXRUNS CGI::SpeedyCGI : MAXRUNS mod_speedycgi : SpeedyMaxruns Default Value : 0 (ie no max)
Description:
Once the perl interpreter has run N times, exit.
Command Line : -Tstr Environment : SPEEDY_TMPBASE CGI::SpeedyCGI : n/a mod_speedycgi : SpeedyTmpbase Default Value : /tmp/speedy
Description:
Use the given prefix for creating temporary files. This must be a filename prefix, not a directory name.
Command Line : -bN Environment : SPEEDY_BUFSIZ_POST CGI::SpeedyCGI : n/a mod_speedycgi : n/a Default Value : 1024
Description:
Use N bytes for the buffer that sends data to the CGI script.
Command Line : -BN Environment : SPEEDY_BUFSIZ_GET CGI::SpeedyCGI : n/a mod_speedycgi : n/a Default Value : 8192
Description:
Use N bytes for the buffer that receives data from the CGI script.
my $sp = CGI::SpeedyCGI->new;
$sp->set_shutdown_handler(sub {$dbh->logout});
$sp->i_am_speedy;
$optname
is
case-insensitive.
$sp->setopt('TIMEOUT', 300);
$optname
is case-insensitive.
$sp->getopt('TIMEOUT');
To install, do the following:
perl Makefile.PL make make test make install
This will install a ``speedy'' binary in the same directory where ``perl'' was installed. If you want to install the optional Apache module, see the README in the apache directory.
Workaround on FreeBSD is to increase the ``maxusers'' value in the kernel config file and compile/install a new kernel. The default value of 32 is too low -- use 256 or more.
poll()
call in speedy.c.
poll()
timeout instead of an alarm to
implement the timeout while waiting for an accept. It's cleaner than a
signal.
Archive is at http://newlug.org/mailArchive/speedycgi
http://daemoninc.com/speedycgi http://www.cpan.org/modules/by-authors/id/H/HO/HORROCKS/
Sam Horrocks Daemon Consulting Inc. http://daemoninc.com sam@daemoninc.com