1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
|
<HTML>
<HEAD>
<TITLE>SpeedyCGI - Speed up perl scripts by running them persistently.</TITLE>
<LINK REV="made" HREF="mailto:root@porky.devel.redhat.com">
</HEAD>
<BODY>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#NAME">NAME</A>
<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
<LI><A HREF="#OPTIONS">OPTIONS</A>
<UL>
<LI><A HREF="#Setting_Option_Values">Setting Option Values</A>
<LI><A HREF="#Context">Context</A>
<LI><A HREF="#Options_Available">Options Available</A>
</UL>
<LI><A HREF="#METHODS">METHODS</A>
<LI><A HREF="#INSTALLATION">INSTALLATION</A>
<UL>
<LI><A HREF="#Binary_Installation">Binary Installation</A>
<LI><A HREF="#Source_Code_Installation">Source Code Installation</A>
<LI><A HREF="#Standard_Install">Standard Install</A>
<LI><A HREF="#Install_in_a_Different_Directory">Install in a Different Directory</A>
<LI><A HREF="#Setuid_Install">Setuid Install</A>
<LI><A HREF="#Apache_Installation">Apache Installation</A>
<LI><A HREF="#Apache_Configuration">Apache Configuration</A>
</UL>
<LI><A HREF="#FREQUENTLY_ASKED_QUESTIONS">FREQUENTLY ASKED QUESTIONS</A>
<LI><A HREF="#USING_GROUPS">USING GROUPS</A>
<LI><A HREF="#DOWNLOADING">DOWNLOADING</A>
<UL>
<LI><A HREF="#Binaries">Binaries</A>
<LI><A HREF="#Source_Code">Source Code</A>
</UL>
<LI><A HREF="#AUTHOR">AUTHOR</A>
<UL>
<LI><A HREF="#Contributors">Contributors</A>
</UL>
<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
<LI><A HREF="#MORE_INFORMATION">MORE INFORMATION</A>
<UL>
<LI><A HREF="#SpeedyCGI_Home_Page">SpeedyCGI Home Page</A>
<LI><A HREF="#Mailing_List">Mailing List</A>
<LI><A HREF="#Bugs_and_Todo_List">Bugs and Todo List</A>
<LI><A HREF="#Japanese_Translation">Japanese Translation</A>
<LI><A HREF="#Benchmarks">Benchmarks</A>
<LI><A HREF="#Success_Stories">Success Stories</A>
<LI><A HREF="#Revision_History">Revision History</A>
<LI><A HREF="#YAPC_2001_Presentation">YAPC 2001 Presentation</A>
</UL>
<LI><A HREF="#COPYRIGHT">COPYRIGHT</A>
</UL>
<!-- INDEX END -->
<HR>
<P>
<H1><A NAME="NAME">NAME</A></H1>
<P>
SpeedyCGI - Speed up perl scripts by running them persistently.
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<P>
<PRE> #!/usr/bin/speedy
</PRE>
<P>
<PRE> ### Your Script Here. For example:
print "Content-type: text/html\n\nHello World!\n";
</PRE>
<P>
<PRE> ##
## Optionally, use the CGI::SpeedyCGI module for various things
##
</PRE>
<P>
<PRE> # Create a SpeedyCGI object
use CGI::SpeedyCGI;
my $sp = CGI::SpeedyCGI->new;
</PRE>
<P>
<PRE> # See if we are running under SpeedyCGI or not.
print "Running under speedy=", $sp->i_am_speedy ? 'yes' : 'no', "\n";
</PRE>
<P>
<PRE> # Register a shutdown handler
$sp->add_shutdown_handler(sub { do something here });
</PRE>
<P>
<PRE> # Register a cleanup handler
$sp->register_cleanup(sub { do something here });
</PRE>
<P>
<PRE> # Set/get some SpeedyCGI options
$sp->setopt('timeout', 30);
print "maxruns=", $sp->getopt('maxruns'), "\n";
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
SpeedyCGI is a way to run perl scripts persistently, which can make them
run much more quickly. A script can be made to to run persistently by
changing the interpreter line at the top of the script from:
<P>
<PRE> #!/usr/bin/perl
</PRE>
<P>
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>
<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
sends data to the perl backend.
</PRE>
<DT><STRONG><A NAME="item_Group">Group</A></STRONG><DD>
<P>
<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>
<P>
Shut down the perl interpreter as soon as this request is done.
<P>
<PRE> $sp->shutdown_next_time
</PRE>
</DL>
<P>
<HR>
<H1><A NAME="INSTALLATION">INSTALLATION</A></H1>
<P>
To install SpeedyCGI you will need to either download a binary package for
your OS, or compile SpeedyCGI from source code. See <A HREF="#DOWNLOADING">DOWNLOADING</A>
for information on where to obtain the source code and binaries.
<P>
<HR>
<H2><A NAME="Binary_Installation">Binary Installation</A></H2>
<P>
Once you have downloaded the binary package for your OS, you'll need to
install it using the normal package tools for your OS. The commands to do
that are:
<DL>
<DT><STRONG><A NAME="item_Linux">Linux</A></STRONG><DD>
<P>
<PRE> rpm -i <filename>
</PRE>
<DT><STRONG><A NAME="item_Solaris">Solaris</A></STRONG><DD>
<P>
<PRE> gunzip <filename>.gz
pkgadd -d <filename>
</PRE>
<DT><STRONG><A NAME="item_BSD">BSD</A></STRONG><DD>
<P>
<PRE> pkg_add <filename>
</PRE>
</DL>
<P>
If you are also installing the apache module you will have to configure
Apache as documented in <A HREF="#Apache_Configuration">Apache Configuration</A>.
<P>
<HR>
<H2><A NAME="Source_Code_Installation">Source Code Installation</A></H2>
<P>
To compile SpeedyCGI you will need perl 5.005_03 or later, and a C
compiler, preferably the same one that your perl distribution was compiled
with. SpeedyCGI is known to work under Solaris, Redhat Linux, FreeBSD and
OpenBSD. There may be problems with other OSes or earlier versions of Perl.
SpeedyCGI may not work with threaded perl -- as of release 2.10, Linux and
Solaris seem to work OK with threaded perl, but FreeBSD does not.
<P>
<HR>
<H2><A NAME="Standard_Install">Standard Install</A></H2>
<P>
To do a standard install from source code, execute the following:
<P>
<PRE> perl Makefile.PL
make
make test
make install
</PRE>
<P>
This will install the speedy and speedy_backend binaries in the same
directory where perl was installed, and the SpeedyCGI.pm module in the
standard perl lib directory. It will also attempt to install the
mod_speedycgi module if you have the command <STRONG>apxs</STRONG> in your path.
<P>
<HR>
<H2><A NAME="Install_in_a_Different_Directory">Install in a Different Directory</A></H2>
<P>
If you don't have permission to install into the standard perl directory,
or if you want to install elsewhere, the easiest way is to compile and
install your own copy of perl in another location, then use your new
version of perl when you run ``perl Makefile.PL''. The SpeedyCGI binaries
and module will then be installed in the same location as the new version
of perl.
<P>
If you can't install your own perl, you can take the following steps:
<UL>
<LI>
<P>
Edit src/optdefs and change the default value for BackendProg to the
location where speedy_backend will be installed.
</UL>
<UL>
<LI>
<P>
Compile as above, then manually copy the speedy and speedy_backend binaries
to where you want to install them.
</UL>
<UL>
<LI>
<P>
If you want to use the CGI::SpeedyCGI module in your code (it's not
required), you will have to use ``use lib'' so it can be located.
</UL>
<P>
<HR>
<H2><A NAME="Setuid_Install">Setuid Install</A></H2>
<P>
SpeedyCGI has limited support for running setuid - installing this way may
compromise the security of your system. To install setuid do the following:
<UL>
<LI>
<P>
Run ``perl Makefile.PL''
</UL>
<UL>
<LI>
<P>
Edit speedy/Makefile and add ``-DIAMSUID'' to the end of the ``DEFINE = ''
line.
</UL>
<UL>
<LI>
<P>
Run make
</UL>
<UL>
<LI>
<P>
Take the resulting ``speedy'' binary and install it suid-root as
/usr/bin/speedy_suid
</UL>
<UL>
<LI>
<P>
Change your setuid scripts to use /usr/bin/speedy_suid as the interpreter.
</UL>
<P>
This has been know to work in Linux and FreeBSD. Solaris will work as long
as the Group option is set to ``none''.
<P>
<HR>
<H2><A NAME="Apache_Installation">Apache Installation</A></H2>
<P>
To compile the optional apache mod_speedycgi module you must have the <STRONG>apxs</STRONG>
command in your path. Redhat includes this command with the
``apache-devel'' RPM, though it may not work properly for installation.
<P>
If the apache installation fails:
<UL>
<LI>
<P>
Copy the mod_speedycgi.so from the mod_speedycgi directory, or from the
mod_speedycgi2/.libs directory, to wherever your apache modules are stored
(try <EM>/usr/lib/apache</EM>)
</UL>
<UL>
<LI>
<P>
Edit your <EM>httpd.conf</EM> (try <EM>/etc/httpd/conf/httpd.conf</EM>) and add the following lines. The path at the end of the LoadModule
directive may be different in your installation -- look at other
LoadModules to see.
<P>
<PRE> LoadModule speedycgi_module modules/mod_speedycgi.so
</PRE>
<P>
If you are using Apache-1, also add:
<P>
<PRE> AddModule mod_speedycgi.c
</PRE>
</UL>
<P>
<HR>
<H2><A NAME="Apache_Configuration">Apache Configuration</A></H2>
<P>
Once mod_speedycgi is installed, it has to be configured to be used for
your perl scripts. There are two methods.
<P>
Warning! The instructions below may compromise the security of your web
site. The security risks associated with SpeedyCGI are similar to those of
regular CGI. If you don't understand the security implications of the
changes below then don't make them.
<OL>
<LI><STRONG><A NAME="item_Path_Configuration">Path Configuration</A></STRONG>
<P>
This is similar to the way <EM>/cgi-bin</EM> works - everything under this path is handled by SpeedyCGI. Add the
following lines near the top of your httpd.conf - this will cause all
scripts in your cgi-bin directory to be handled by SpeedyCGI when they are
accessed as <EM>/speedy/script-name</EM>.
<P>
<PRE> Alias /speedy/ /home/httpd/cgi-bin/
<Location /speedy>
SetHandler speedycgi-script
Options ExecCGI
allow from all
</Location>
</PRE>
<LI><STRONG><A NAME="item_File_Extension_Configuration">File Extension Configuration</A></STRONG>
<P>
This will make SpeedyCGI handle all files with a certain extension, similar
to the way .cgi files work. Add the following lines near the top of your
httpd.conf file - this will set up the file extension ``.speedy'' to be
handled by SpeedyCGI.
<P>
<PRE> AddHandler speedycgi-script .speedy
<Location />
Options ExecCGI
</Location>
</PRE>
</OL>
<P>
<HR>
<H1><A NAME="FREQUENTLY_ASKED_QUESTIONS">FREQUENTLY ASKED QUESTIONS</A></H1>
<DL>
<DT><STRONG><A NAME="item_How">How does the speedy front end connect to the back end process?</A></STRONG><DD>
<P>
Via a Unix socket in <EM>/tmp</EM>. A queue is kept in a shared file in <EM>/tmp</EM>
that holds an entry for each process. In that queue are the pids of the
perl processes waiting for connections. The frontend pulls a process out of
this queue, connects to its socket, sends over the environment and argv,
and then uses this socket for stdin/stdout to the perl process.
</DL>
<DL>
<DT><STRONG><A NAME="item_If">If another request comes in while SpeedyCGI script is running, does the client
have to wait or is another process started? Is there a way to set a limit
on how many processes get started?</A></STRONG><DD>
<P>
If another request comes while all the perl processes are busy, then
another perl process is started. Just like in regular perl there is
normally no limit on how many processes get started. But, the processes are
only started when the load is so high that they're necessary. If the load
goes down, the processes will die off due to inactivity, unless you disable
the timeout.
<P>
Starting in version 1.8.3 an option was added to limit the number of perl
backends running. See <STRONG>MaxBackends</STRONG> in <A HREF="#Options_Available">Options Available</A>
above.
</DL>
<DL>
<DT><STRONG>How much of perl's state is kept when speedy starts another request?
Do globals keep their values? Are destructors run after the request?</STRONG><DD>
<P>
Globals keep their values. Nothing is destroyed after the request.
STDIN/STDOUT/STDERR are closed -- other files are not. <CODE>%ENV</CODE> and <CODE>@ARGV</CODE>
are the only globals changed between requests.
</DL>
<DL>
<DT><STRONG>How can I make sure speedy restarts when I edit a perl library used
by the CGI?</STRONG><DD>
<P>
Do a touch on the main cgi file that is executed. The mtime on the main
file is checked each time the front-end runs.
</DL>
<DL>
<DT><STRONG><A NAME="item_Do">Do I need to be root to install and/or run SpeedyCGI?</A></STRONG><DD>
<P>
No, root is not required.
</DL>
<DL>
<DT><STRONG>How can I determine if my perl app needs to be changed to work with
speedy? Or is there no modification necessary?</STRONG><DD>
<P>
You may have to make modifications.
<P>
Globals retain their values between runs, which can be good for keeping
persistent database handles for example, or bad if your code assumes
they're undefined.
<P>
Also, if you create global variables with ``my'', you shouldn't try to
reference those variables from within a subroutine - you should pass them
into the subroutine instead. Or better yet just declare global variables
with ``use vars'' instead of ``my'' to avoid the problem altogether.
<P>
Here's a good explanation of the problem - it's for mod_perl, but the same
thing applies to speedycgi:
<P>
<PRE> <A HREF="http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___Scoped_Variable_in_Nested_Subroutines">http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___Scoped_Variable_in_Nested_Subroutines</A>
</PRE>
<P>
If all else fails you can disable persistence by setting MaxRuns to 1. The
only benefit of this over normal perl is that speedy will pre-compile your
script.
</DL>
<DL>
<DT><STRONG>How do I keep a persistent connection to a database?</STRONG><DD>
<P>
Since globals retain their values between runs, the best way to do this is
to store the connection in a global variable, then check on each run to see
if that variable is already defined.
<P>
For example, if your code has an ``open_db_connection'' subroutine that
returns a database connection handle, you can use the code below to keep a
persistent connection:
<P>
<PRE> use vars qw($dbh);
unless (defined($dbh)) {
$dbh = &open_db_connection;
}
</PRE>
<P>
This code will store a persistent database connection handle in the global
variable ``$dbh'' and only initialize it the first time the code is run.
During subsequent runs, the existing connection is re-used.
<P>
You may also want to check the connection each time before using it, in
case it is not working for some reason. So, assuming you have a subroutine
named ``db_connection_ok'' that returns true if the db connection is
working, you can use code like this:
<P>
<PRE> use vars qw($dbh);
unless (defined($dbh) && &db_connection_ok($dbh)) {
$dbh = &open_db_connection;
}
</PRE>
</DL>
<DL>
<DT><STRONG><A NAME="item_Why">Why do scripts with persistent Oracle database connections hang?</A></STRONG><DD>
<P>
When using an IPC connection to Oracle, an oracle process is fork'ed and
exec'ed and keeps the stdout connection open, so that the web server never
gets an EOF. To fix the problem, either switch to using a TCP connection to
the database, or add the following perl code somewhere before the
DBI->connect statement:
<P>
<PRE> use Fcntl;
fcntl(STDOUT, F_SETFD, FD_CLOEXEC);
</PRE>
<P>
This will set the close-on-exec flag on standard out so it is closed when
oracle is exec'ed.
</DL>
<P>
<HR>
<H1><A NAME="USING_GROUPS">USING GROUPS</A></H1>
<P>
The group feature in SpeedyCGI can be used to help reduce the amount of
memory used by the perl interpreters. By default groups are not used (group
name is ``none''), and each perl script is given its own set of perl
interpreters. Each perl interpreter is also a separate system process.
<P>
When grouping is used, perl interpreters and perl scripts are put in a
group. All perl interpreters in a group can run perl scripts in the same
group. What this means is that by putting all your scripts into one group,
there could be one perl interpreter running all the perl scripts on your
system. This can greatly reduce your memory needs when running lots of
different perl scripts.
<P>
SpeedyCGI group names are entities unto themselves. They are not associated
with Unix groups, or with the Group directive in Apache. Expect for the two
special group names ``none'' and ``default'', all group names are created
by the user of SpeedyCGI using the Group option described in <A HREF="#OPTIONS">OPTIONS</A>
<P>
If you want the maximum amount of grouping possible then you should run all
scripts with the group option set to ``default''. This the group name used
if you just specify ``-g'' on the command line without an explicit group
name. When you do this, you will get the fewest number of perl interpreters
possible - any perl interpreter will be able to run any of your perl
scripts.
<P>
Although using group ``default'' for all scripts results in the most
efficient use of resources, it's not always possible or desirable to do
this. You may want to use other group names for the following reasons:
<UL>
<LI><STRONG><A NAME="item_To">To isolate misbehaving scripts, or scripts that don't work in groups.</A></STRONG>
<P>
Some scripts won't work in groups. When perl scripts are grouped together
they are each given their own unique package name - they are not run out of
the ``main'' package as they normally would be. So, for example, a script
that explicitly uses ``main'' somewhere in its code to find its subroutines
or variables probably won't work in groups. In this case, it's probably
best to run such a script with group ``none'', so it's compiled and run out
of package main, and always given its own interpreter.
<P>
In other cases, scripts may make changes to included packages, etc, that
may break other scripts running in the same interpreter. In this case such
scripts can be given their own group name (like ``pariah'') to keep them
away from scripts they are incompatible with. The rest of your scripts can
then run out of group ``default''. This will ensure that the ``pariah''
scripts won't run within the same interpreter as the other scripts.
</UL>
<UL>
<LI><STRONG><A NAME="item_To">To pass different perl or SpeedyCGI parameters to different scripts.</A></STRONG>
<P>
You may want to use separate groups to create different policies for
different scripts.
<P>
For example, you may have an email application that contains ten perl
scripts, and since the common perl code used in this application has a bad
memory leak, you want to use a MaxRuns setting of 5 for all of these
scripts. You want to run all your other scripts with a normal MaxRuns
setting. To accomplish this you can edit the ten email application scripts,
and at the top use the line:
<P>
<PRE> #!/usr/bin/speedy -- -gmail -r5
</PRE>
<P>
In the rest of your perl scripts you can use:
<P>
<PRE> #!/usr/bin/speedy -- -g
</PRE>
<P>
What this will do is put the ten email scripts into a group of their own
(named ``mail'') and give them all the default MaxRuns value of 5. All
other scripts will be put into the group named ``default'', and this group
will have a normal MaxRuns setting.
</UL>
<P>
<HR>
<H1><A NAME="DOWNLOADING">DOWNLOADING</A></H1>
<P>
<HR>
<H2><A NAME="Binaries">Binaries</A></H2>
<P>
Binaries for many OSes can be found at:
<P>
<PRE> <A HREF="http://daemoninc.com/SpeedyCGI/download.html">http://daemoninc.com/SpeedyCGI/download.html</A>
</PRE>
<P>
<HR>
<H2><A NAME="Source_Code">Source Code</A></H2>
<P>
The standard source code distribution can be retrieved from any CPAN mirror
or from:
<P>
<PRE> <A HREF="http://daemoninc.com/SpeedyCGI/download.html">http://daemoninc.com/SpeedyCGI/download.html</A>
<A HREF="http://www.cpan.org/modules/by-authors/id/H/HO/HORROCKS/">http://www.cpan.org/modules/by-authors/id/H/HO/HORROCKS/</A>
</PRE>
<P>
The latest development code can be obtained from the SourceForge CVS
repository using the following commands:
<P>
<PRE> cvs -d:pserver:anonymous@cvs.SpeedyCGI.sourceforge.net:/cvsroot/speedycgi login
cvs -z3 -d:pserver:anonymous@cvs.SpeedyCGI.sourceforge.net:/cvsroot/speedycgi co 2.x
</PRE>
<P>
Press Enter when prompted for a password.
<P>
<HR>
<H1><A NAME="AUTHOR">AUTHOR</A></H1>
<P>
<PRE> Sam Horrocks
<A HREF="http://daemoninc.com">http://daemoninc.com</A>
sam@daemoninc.com
</PRE>
<P>
<HR>
<H2><A NAME="Contributors">Contributors</A></H2>
<P>
A lot of people have helped out with code, patches, ideas, resources, etc.
I'm sure I'm missing someone here - if so, please drop me an email.
<UL>
<LI>
<P>
Gunther Birznieks
<LI>
<P>
Diana Eichert
<LI>
<P>
Takanori Kawai
<LI>
<P>
Robert Klep
<LI>
<P>
Marc Lehmann
<LI>
<P>
James McGregor
<LI>
<P>
Josh Rabinowitz
<LI>
<P>
Dave Parker
<LI>
<P>
Craig Sanders
<LI>
<P>
Joseph Wang
</UL>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<CODE>perl(1),</CODE> <CODE>httpd(8),</CODE> <CODE>apxs(8).</CODE>
<P>
<HR>
<H1><A NAME="MORE_INFORMATION">MORE INFORMATION</A></H1>
<P>
<HR>
<H2><A NAME="SpeedyCGI_Home_Page">SpeedyCGI Home Page</A></H2>
<P>
<A
HREF="http://daemoninc.com/SpeedyCGI/">http://daemoninc.com/SpeedyCGI/</A>
<P>
<HR>
<H2><A NAME="Mailing_List">Mailing List</A></H2>
<UL>
<LI>
<P>
SpeedyCGI users mailing list - <A
HREF="mailto:speedycgi-users@lists.sourceforge.net.">speedycgi-users@lists.sourceforge.net.</A>
Archives and subscription information are at <A
HREF="http://lists.sourceforge.net/lists/listinfo/speedycgi-users">http://lists.sourceforge.net/lists/listinfo/speedycgi-users</A>
</UL>
<UL>
<LI>
<P>
SpeedyCGI announcements mailing list - <A
HREF="mailto:speedycgi-announce@lists.sourceforge.net.">speedycgi-announce@lists.sourceforge.net.</A>
Archives and subscription information are at <A
HREF="http://lists.sourceforge.net/lists/listinfo/speedycgi-announce">http://lists.sourceforge.net/lists/listinfo/speedycgi-announce</A>
</UL>
<P>
<HR>
<H2><A NAME="Bugs_and_Todo_List">Bugs and Todo List</A></H2>
<P>
Please report any bugs or requests for changes to the mailing list.
<P>
The current bugs / todo list can be found at <A
HREF="http://www.sourceforge.net/projects/speedycgi/.">http://www.sourceforge.net/projects/speedycgi/.</A>
Go to the Bug Tracking menu and select the group ``bug'' for bugs, or the
group ``rfe'' for the todo list.
<P>
<HR>
<H2><A NAME="Japanese_Translation">Japanese Translation</A></H2>
<P>
<A
HREF="http://member.nifty.ne.jp/hippo2000/perltips/CGI/SpeedyCGI.htm">http://member.nifty.ne.jp/hippo2000/perltips/CGI/SpeedyCGI.htm</A>
<P>
<HR>
<H2><A NAME="Benchmarks">Benchmarks</A></H2>
<P>
<A
HREF="http://daemoninc.com/SpeedyCGI/benchmarks/">http://daemoninc.com/SpeedyCGI/benchmarks/</A>
<P>
<HR>
<H2><A NAME="Success_Stories">Success Stories</A></H2>
<P>
<A
HREF="http://daemoninc.com/SpeedyCGI/success_stories/">http://daemoninc.com/SpeedyCGI/success_stories/</A>
<P>
<HR>
<H2><A NAME="Revision_History">Revision History</A></H2>
<P>
<A
HREF="http://daemoninc.com/SpeedyCGI/CGI-SpeedyCGI/Changes">http://daemoninc.com/SpeedyCGI/CGI-SpeedyCGI/Changes</A>
<P>
<HR>
<H2><A NAME="YAPC_2001_Presentation">YAPC 2001 Presentation</A></H2>
<P>
I gave an Introduction to SpeedyCGI talk at YAPC 2001. It can be found at
<A
HREF="http://daemoninc.com/SpeedyCGI/yapc_2001/">http://daemoninc.com/SpeedyCGI/yapc_2001/</A>
<P>
<HR>
<H1><A NAME="COPYRIGHT">COPYRIGHT</A></H1>
<P>
Copyright (C) 2003 Sam Horrocks
<P>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
<P>
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
<P>
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<P>
This product includes software developed by the Apache Software Foundation
(http://www.apache.org/).
</BODY>
</HTML>
|