-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.html
907 lines (567 loc) · 34.4 KB
/
README.html
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
<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#SYNOPSIS">SYNOPSIS</a></li>
<li><a href="#DESCRIPTION">DESCRIPTION</a></li>
<li><a href="#OPTIONS">OPTIONS</a>
<ul>
<li><a href="#Setting-Option-Values">Setting Option Values</a></li>
<li><a href="#Context">Context</a></li>
<li><a href="#Options-Available">Options Available</a></li>
</ul>
</li>
<li><a href="#METHODS">METHODS</a></li>
<li><a href="#INSTALLATION">INSTALLATION</a>
<ul>
<li><a href="#Binary-Installation">Binary Installation</a></li>
<li><a href="#Source-Code-Installation">Source Code Installation</a></li>
<li><a href="#Standard-Install">Standard Install</a></li>
<li><a href="#Install-in-a-Different-Directory">Install in a Different Directory</a></li>
<li><a href="#Setuid-Install">Setuid Install</a></li>
<li><a href="#Apache-Installation">Apache Installation</a></li>
<li><a href="#Apache-Configuration">Apache Configuration</a></li>
</ul>
</li>
<li><a href="#FREQUENTLY-ASKED-QUESTIONS">FREQUENTLY ASKED QUESTIONS</a></li>
<li><a href="#USING-GROUPS">USING GROUPS</a></li>
<li><a href="#DOWNLOADING">DOWNLOADING</a>
<ul>
<li><a href="#Binaries">Binaries</a></li>
<li><a href="#Source-Code">Source Code</a></li>
</ul>
</li>
<li><a href="#AUTHOR">AUTHOR</a>
<ul>
<li><a href="#Contributors">Contributors</a></li>
</ul>
</li>
<li><a href="#SEE-ALSO">SEE ALSO</a></li>
<li><a href="#MORE-INFORMATION">MORE INFORMATION</a>
<ul>
<li><a href="#SpeedyCGI-Home-Page">SpeedyCGI Home Page</a></li>
<li><a href="#Mailing-List">Mailing List</a></li>
<li><a href="#Bugs-and-Todo-List">Bugs and Todo List</a></li>
<li><a href="#Japanese-Translation">Japanese Translation</a></li>
<li><a href="#Benchmarks">Benchmarks</a></li>
<li><a href="#Success-Stories">Success Stories</a></li>
<li><a href="#Revision-History">Revision History</a></li>
<li><a href="#YAPC-2001-Presentation">YAPC 2001 Presentation</a></li>
</ul>
</li>
<li><a href="#COPYRIGHT">COPYRIGHT</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>SpeedyCGI - Speed up perl scripts by running them persistently.</p>
<h1 id="SYNOPSIS">SYNOPSIS</h1>
<pre><code> #!/usr/bin/speedy
### Your Script Here. For example:
print "Content-type: text/html\n\nHello World!\n";
##
## 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";
# Register a shutdown handler
$sp->add_shutdown_handler(sub { do something here });
# Register a cleanup handler
$sp->register_cleanup(sub { do something here });
# Set/get some SpeedyCGI options
$sp->setopt('timeout', 30);
print "maxruns=", $sp->getopt('maxruns'), "\n";</code></pre>
<h1 id="DESCRIPTION">DESCRIPTION</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><code> #!/usr/bin/perl</code></pre>
<p>to</p>
<pre><code> #!/usr/bin/speedy</code></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>
<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>
<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>
<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>
<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>
<h1 id="OPTIONS">OPTIONS</h1>
<h2 id="Setting-Option-Values">Setting Option Values</h2>
<p>SpeedyCGI options can be set in several ways:</p>
<dl>
<dt id="Command-Line">Command Line</dt>
<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>
<p>For example the line:</p>
<pre><code> #!/usr/bin/speedy -w -- -t300</code></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.</p>
</dd>
</dl>
<dl>
<dt id="Environment">Environment</dt>
<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.</p>
</dd>
</dl>
<dl>
<dt id="Module">Module</dt>
<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.</p>
</dd>
</dl>
<dl>
<dt id="Apache">Apache</dt>
<dd>
<p>If you are using the optional Apache module, SpeedyCGI options can be set in the <i>httpd.conf</i> 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.</p>
<p>Note that these variables are global. There is currently no way to run different scripts with different SpeedyCGI options when they are run from the Apache module. Any <Directory> or <Location> contexts have no effect on the scope of the SpeedyCGI options. When the same SpeedyCGI option is set several times, the last one overrides the others.</p>
</dd>
</dl>
<h2 id="Context">Context</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:</p>
<dl>
<dt id="speedy">speedy</dt>
<dd>
<p>The command-line "speedy" program, used normally with #! at the top of your script or from a shell prompt.</p>
</dd>
</dl>
<dl>
<dt id="mod_speedycgi">mod_speedycgi</dt>
<dd>
<p>The optional Apache mod_speedycgi module.</p>
</dd>
</dl>
<dl>
<dt id="module">module</dt>
<dd>
<p>During perl execution via the CGI::SpeedyCGI module's getopt/setopt methods.</p>
</dd>
</dl>
<h2 id="Options-Available">Options Available</h2>
<dl>
<dt id="BackendProg">BackendProg</dt>
<dd>
<pre><code> Command Line : -p<string>
Default Value : "/usr/bin/speedy_backend"
Context : mod_speedycgi, speedy
Description:
Path to the speedy backend program.</code></pre>
</dd>
<dt id="BufsizGet">BufsizGet</dt>
<dd>
<pre><code> Command Line : -B<number>
Default Value : 131072
Context : speedy
Description:
Use <number> bytes as the maximum size for the buffer that
receives data from the perl backend.</code></pre>
</dd>
<dt id="BufsizPost">BufsizPost</dt>
<dd>
<pre><code> Command Line : -b<number>
Default Value : 131072
Context : speedy
Description:
Use <number> bytes as the maximum size for the buffer that
sends data to the perl backend.</code></pre>
</dd>
<dt id="Group">Group</dt>
<dd>
<pre><code> Command Line : -g<string>
Default Value : "none"
Context : mod_speedycgi, speedy
Description:
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.</code></pre>
</dd>
<dt id="MaxBackends">MaxBackends</dt>
<dd>
<pre><code> Command Line : -M<number>
Default Value : 0 (no max)
Context : mod_speedycgi, speedy
Description:
If non-zero, limits the number of speedy backends running
for this perl script to <number>.</code></pre>
</dd>
<dt id="MaxRuns">MaxRuns</dt>
<dd>
<pre><code> Command Line : -r<number>
Default Value : 500
Context : mod_speedycgi, module, speedy
Description:
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.</code></pre>
</dd>
<dt id="PerlArgs">PerlArgs</dt>
<dd>
<pre><code> Command Line : N/A
Default Value : ""
Context : mod_speedycgi
Description:
Command-line options to pass to the perl interpreter.</code></pre>
</dd>
<dt id="Timeout">Timeout</dt>
<dd>
<pre><code> Command Line : -t<number>
Default Value : 3600 (one hour)
Context : mod_speedycgi, module, speedy
Description:
If no new requests have been received after <number>
seconds, exit the persistent perl interpreter. Zero
indicates no timeout.</code></pre>
</dd>
<dt id="TmpBase">TmpBase</dt>
<dd>
<pre><code> Command Line : -T<string>
Default Value : "/tmp/speedy"
Context : mod_speedycgi, speedy
Description:
Use the given prefix for creating temporary files. This
must be a filename prefix, not a directory name.</code></pre>
</dd>
<dt id="Version">Version</dt>
<dd>
<pre><code> Command Line : -v
Context : speedy
Description:
Print the SpeedyCGI version and exit.</code></pre>
</dd>
</dl>
<h1 id="METHODS">METHODS</h1>
<p>The following methods are available in the CGI::SpeedyCGI module.</p>
<dl>
<dt id="new">new</dt>
<dd>
<p>Create a new CGI::SpeedyCGI object.</p>
<pre><code> my $sp = CGI::SpeedyCGI->new;</code></pre>
</dd>
<dt id="register_cleanup-function_ref-">register_cleanup($function_ref)</dt>
<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><code> $sp->register_cleanup(\&cleanup_func);</code></pre>
</dd>
<dt id="add_shutdown_handler-function_ref-">add_shutdown_handler($function_ref)</dt>
<dd>
<p>Add a function to the list of functions that will be called right before the perl interpreter exits. This is <b>not</b> 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><code> $sp->add_shutdown_handler(sub {$dbh->logout});</code></pre>
</dd>
<dt id="set_shutdown_handler-function_ref-">set_shutdown_handler($function_ref)</dt>
<dd>
<p>Deprecated. Similar to <code>add_shutdown_handler</code>, but only allows for a single function to be registered.</p>
<pre><code> $sp->set_shutdown_handler(sub {$dbh->logout});</code></pre>
</dd>
<dt id="i_am_speedy">i_am_speedy</dt>
<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><code> $sp->i_am_speedy;</code></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><code> if (eval {require CGI::SpeedyCGI} && CGI::SpeedyCGI->i_am_speedy) {
Do something SpeedyCGI specific here...</code></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><code> $CGI::SpeedyCGI::i_am_speedy</code></pre>
</dd>
<dt id="setopt-optname-value-">setopt($optname, $value)</dt>
<dd>
<p>Set one of the SpeedyCGI options given in <a href="#Options-Available">"Options Available"</a>. Returns the option's previous value. $optname is case-insensitive.</p>
<pre><code> $sp->setopt('TIMEOUT', 300);</code></pre>
</dd>
<dt id="getopt-optname-">getopt($optname)</dt>
<dd>
<p>Return the current value of one of the SpeedyCGI options. $optname is case-insensitive.</p>
<pre><code> $sp->getopt('TIMEOUT');</code></pre>
</dd>
<dt id="shutdown_now">shutdown_now</dt>
<dd>
<p>Shut down the perl interpreter right away. This function does not return.</p>
<pre><code> $sp->shutdown_now</code></pre>
</dd>
<dt id="shutdown_next_time">shutdown_next_time</dt>
<dd>
<p>Shut down the perl interpreter as soon as this request is done.</p>
<pre><code> $sp->shutdown_next_time</code></pre>
</dd>
</dl>
<h1 id="INSTALLATION">INSTALLATION</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>
<h2 id="Binary-Installation">Binary Installation</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:</p>
<dl>
<dt id="Linux">Linux</dt>
<dd>
<pre><code> rpm -i <filename></code></pre>
</dd>
<dt id="Solaris">Solaris</dt>
<dd>
<pre><code> gunzip <filename>.gz
pkgadd -d <filename></code></pre>
</dd>
<dt id="BSD">BSD</dt>
<dd>
<pre><code> pkg_add <filename></code></pre>
</dd>
</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>
<h2 id="Source-Code-Installation">Source Code Installation</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>
<h2 id="Standard-Install">Standard Install</h2>
<p>To do a standard install from source code, execute the following:</p>
<pre><code> perl Makefile.PL
make
make test
make install</code></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 <b>apxs</b> in your path.</p>
<h2 id="Install-in-a-Different-Directory">Install in a Different Directory</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>
<p>If you can't install your own perl, you can take the following steps:</p>
<ul>
<li><p>Edit src/optdefs and change the default value for BackendProg to the location where speedy_backend will be installed.</p>
</li>
</ul>
<ul>
<li><p>Compile as above, then manually copy the speedy and speedy_backend binaries to where you want to install them.</p>
</li>
</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.</p>
</li>
</ul>
<h2 id="Setuid-Install">Setuid Install</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:</p>
<ul>
<li><p>Run "perl Makefile.PL"</p>
</li>
</ul>
<ul>
<li><p>Edit speedy/Makefile and add "-DIAMSUID" to the end of the "DEFINE = " line.</p>
</li>
</ul>
<ul>
<li><p>Run make</p>
</li>
</ul>
<ul>
<li><p>Take the resulting "speedy" binary and install it suid-root as /usr/bin/speedy_suid</p>
</li>
</ul>
<ul>
<li><p>Change your setuid scripts to use /usr/bin/speedy_suid as the interpreter.</p>
</li>
</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>
<h2 id="Apache-Installation">Apache Installation</h2>
<p>To compile the optional apache mod_speedycgi module you must have the <b>apxs</b> command in your path. Redhat includes this command with the "apache-devel" RPM, though it may not work properly for installation.</p>
<p>If the apache installation fails:</p>
<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 <i>/usr/lib/apache</i>)</p>
</li>
</ul>
<ul>
<li><p>Edit your <i>httpd.conf</i> (try <i>/etc/httpd/conf/httpd.conf</i>) 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><code> LoadModule speedycgi_module modules/mod_speedycgi.so</code></pre>
<p>If you are using Apache-1, also add:</p>
<pre><code> AddModule mod_speedycgi.c</code></pre>
</li>
</ul>
<h2 id="Apache-Configuration">Apache Configuration</h2>
<p>Once mod_speedycgi is installed, it has to be configured to be used for your perl scripts. There are two methods.</p>
<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.</p>
<dl>
<dt id="Path-Configuration">1. Path Configuration</dt>
<dd>
<p>This is similar to the way <i>/cgi-bin</i> 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 <i>/speedy/script-name</i>.</p>
<pre><code> Alias /speedy/ /home/httpd/cgi-bin/
<Location /speedy>
SetHandler speedycgi-script
Options ExecCGI
allow from all
</Location></code></pre>
</dd>
<dt id="File-Extension-Configuration">2. File Extension Configuration</dt>
<dd>
<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><code> AddHandler speedycgi-script .speedy
<Location />
Options ExecCGI
</Location></code></pre>
</dd>
</dl>
<h1 id="FREQUENTLY-ASKED-QUESTIONS">FREQUENTLY ASKED QUESTIONS</h1>
<dl>
<dt id="How-does-the-speedy-front-end-connect-to-the-back-end-process-">How does the speedy front end connect to the back end process?</dt>
<dd>
<p>Via a Unix socket in <i>/tmp</i>. A queue is kept in a shared file in <i>/tmp</i> 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.</p>
</dd>
</dl>
<dl>
<dt id="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-">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?</dt>
<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>
<p>Starting in version 1.8.3 an option was added to limit the number of perl backends running. See <b>MaxBackends</b> in <a href="#Options-Available">"Options Available"</a> above.</p>
</dd>
</dl>
<dl>
<dt id="How-much-of-perls-state-is-kept-when-speedy-starts-another-request-Do-globals-keep-their-values-Are-destructors-run-after-the-request-">How much of perl's state is kept when speedy starts another request? Do globals keep their values? Are destructors run after the request?</dt>
<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.</p>
</dd>
</dl>
<dl>
<dt id="How-can-I-make-sure-speedy-restarts-when-I-edit-a-perl-library-used-by-the-CGI-">How can I make sure speedy restarts when I edit a perl library used by the CGI?</dt>
<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.</p>
</dd>
</dl>
<dl>
<dt id="Do-I-need-to-be-root-to-install-and-or-run-SpeedyCGI-">Do I need to be root to install and/or run SpeedyCGI?</dt>
<dd>
<p>No, root is not required.</p>
</dd>
</dl>
<dl>
<dt id="How-can-I-determine-if-my-perl-app-needs-to-be-changed-to-work-with-speedy-Or-is-there-no-modification-necessary-">How can I determine if my perl app needs to be changed to work with speedy? Or is there no modification necessary?</dt>
<dd>
<p>You may have to make modifications.</p>
<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>
<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>
<p>Here's a good explanation of the problem - it's for mod_perl, but the same thing applies to speedycgi:</p>
<pre><code> http://perl.apache.org/docs/general/perl_reference/perl_reference.html#my___Scoped_Variable_in_Nested_Subroutines</code></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.</p>
</dd>
</dl>
<dl>
<dt id="How-do-I-keep-a-persistent-connection-to-a-database-">How do I keep a persistent connection to a database?</dt>
<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>
<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><code> use vars qw($dbh);
unless (defined($dbh)) {
$dbh = &open_db_connection;
}</code></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>
<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><code> use vars qw($dbh);
unless (defined($dbh) && &db_connection_ok($dbh)) {
$dbh = &open_db_connection;
}</code></pre>
</dd>
</dl>
<dl>
<dt id="Why-do-scripts-with-persistent-Oracle-database-connections-hang-">Why do scripts with persistent Oracle database connections hang?</dt>
<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><code> use Fcntl;
fcntl(STDOUT, F_SETFD, FD_CLOEXEC);</code></pre>
<p>This will set the close-on-exec flag on standard out so it is closed when oracle is exec'ed.</p>
</dd>
</dl>
<h1 id="USING-GROUPS">USING GROUPS</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>
<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>
<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>
<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>
<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:</p>
<ul>
<li><p>To isolate misbehaving scripts, or scripts that don't work in groups.</p>
<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>
<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.</p>
</li>
</ul>
<ul>
<li><p>To pass different perl or SpeedyCGI parameters to different scripts.</p>
<p>You may want to use separate groups to create different policies for different scripts.</p>
<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><code> #!/usr/bin/speedy -- -gmail -r5</code></pre>
<p>In the rest of your perl scripts you can use:</p>
<pre><code> #!/usr/bin/speedy -- -g</code></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.</p>
</li>
</ul>
<h1 id="DOWNLOADING">DOWNLOADING</h1>
<h2 id="Binaries">Binaries</h2>
<p>Binaries for many OSes can be found at:</p>
<pre><code> http://daemoninc.com/SpeedyCGI/download.html</code></pre>
<h2 id="Source-Code">Source Code</h2>
<p>The standard source code distribution can be retrieved from any CPAN mirror or from:</p>
<pre><code> http://daemoninc.com/SpeedyCGI/download.html
http://www.cpan.org/modules/by-authors/id/H/HO/HORROCKS/</code></pre>
<p>The latest development code can be obtained from the SourceForge CVS repository using the following commands:</p>
<pre><code> cvs -d:pserver:[email protected]:/cvsroot/speedycgi login
cvs -z3 -d:pserver:[email protected]:/cvsroot/speedycgi co 2.x</code></pre>
<p>Press Enter when prompted for a password.</p>
<h1 id="AUTHOR">AUTHOR</h1>
<pre><code> Sam Horrocks
http://daemoninc.com
[email protected]</code></pre>
<h2 id="Contributors">Contributors</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.</p>
<ul>
<li><p>Gunther Birznieks</p>
</li>
<li><p>Diana Eichert</p>
</li>
<li><p>Takanori Kawai</p>
</li>
<li><p>Robert Klep</p>
</li>
<li><p>Marc Lehmann</p>
</li>
<li><p>James McGregor</p>
</li>
<li><p>Josh Rabinowitz</p>
</li>
<li><p>Dave Parker</p>
</li>
<li><p>Craig Sanders</p>
</li>
<li><p>Joseph Wang</p>
</li>
</ul>
<h1 id="SEE-ALSO">SEE ALSO</h1>
<p>perl(1), httpd(8), apxs(8).</p>
<h1 id="MORE-INFORMATION">MORE INFORMATION</h1>
<h2 id="SpeedyCGI-Home-Page">SpeedyCGI Home Page</h2>
<p>http://daemoninc.com/SpeedyCGI/</p>
<h2 id="Mailing-List">Mailing List</h2>
<ul>
<li><p>SpeedyCGI users mailing list - [email protected]. Archives and subscription information are at http://lists.sourceforge.net/lists/listinfo/speedycgi-users</p>
</li>
</ul>
<ul>
<li><p>SpeedyCGI announcements mailing list - [email protected]. Archives and subscription information are at http://lists.sourceforge.net/lists/listinfo/speedycgi-announce</p>
</li>
</ul>
<h2 id="Bugs-and-Todo-List">Bugs and Todo List</h2>
<p>Please report any bugs or requests for changes to the mailing list.</p>
<p>The current bugs / todo list can be found at http://www.sourceforge.net/projects/speedycgi/. Go to the Bug Tracking menu and select the group "bug" for bugs, or the group "rfe" for the todo list.</p>
<h2 id="Japanese-Translation">Japanese Translation</h2>
<p>http://member.nifty.ne.jp/hippo2000/perltips/CGI/SpeedyCGI.htm</p>
<h2 id="Benchmarks">Benchmarks</h2>
<p>http://daemoninc.com/SpeedyCGI/benchmarks/</p>
<h2 id="Success-Stories">Success Stories</h2>
<p>http://daemoninc.com/SpeedyCGI/success_stories/</p>
<h2 id="Revision-History">Revision History</h2>
<p>http://daemoninc.com/SpeedyCGI/CGI-SpeedyCGI/Changes</p>
<h2 id="YAPC-2001-Presentation">YAPC 2001 Presentation</h2>
<p>I gave an Introduction to SpeedyCGI talk at YAPC 2001. It can be found at http://daemoninc.com/SpeedyCGI/yapc_2001/</p>
<h1 id="COPYRIGHT">COPYRIGHT</h1>
<p>Copyright (C) 2003 Sam Horrocks</p>
<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>
<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>
<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>
<p>This product includes software developed by the Apache Software Foundation (http://www.apache.org/).</p>
</body>
</html>