FCGI-Spawn

 view release on metacpan or  search on metacpan

bin/fcgi_spawn  view on Meta::CPAN

Those are optional:

  -e               Redefine the exit() Perl builtin function to prevent the
spawned persistent processes from exiting and starting again when your
application(s) exit;
  -pl              Evaluate the:

=head2 Preload Scripts from the configuration directory

You can use preload scripts for modules preload and initialization, similarly to the what is the apache's C<startup.pl> is attended for in the mod_perl's world , although C<fcgi_spawn> doesn't execute them from the root ( C<uid = 0> ) user. ( while a...
Typically, good results are achieved when you try to execute the dummy index page of the web aplication in them, because it loads the most necessary modules of the application. If you have no errors when execute that perl script ( obviously C<index.p...

Preload scripts are to be located in the configuraion directory with the names C<preload_nonprepared_XX.pl> and C<preload_prepared_XX.pl>, respectively. The C<XX> here means a number of the execution sequence, as you may wish to C<use SomeModule> on ...

Predefined symbols for preload scripts are:

=over

=item $spawn

the L<FCGI::Spawn|FCGI::Spawn> object.

It is useful to do the trick like this for your CGI app:

        $FCGI::Spawn::fcgi = new CGI;
        $spawn->callout( '/path/to/your/CGI/app.pl', $FCGI::Spawn::fcgi );
        undef $FCGI::Spawn::fcgi;

( C<CGI.pm.patch> supplied in the source package is required for this to work best. )
This loads the most of your application's code into memory in the 'nonprepared' script before the daemon to fork() which is the main to know about what the L<FCGI::Spawn's prepare|FCGI::Spawn/prepare> is.

=item CALLED_OUT

the label to go to with the exit() Perl builtin redefined ( '-e' command line parameter ).

Should be contained in the code reference supplied as a L<callout|FCGI::Spawn/new({hash parameters})> property of the $spawn, the C<FCGI::Spawn object>. This is to keep the exit()'ed CGI application from exiting the FastCGI connection C<accept()> loo...
 
        $spawn->{ callout } =  sub{ do shift;
        CALLED_OUT: eval ' $Bugzilla::_request_cache = { }; '
          if defined( $Bugzilla::_request_cache ) and scalar keys %{ $Bugzilla::_request_cache };
        };

=back

=item $OURS

Hash reference to keep scalar variables in between preload eval()s. Those are to be restored in preload scripts like this:

				map{ ${ $main::{ $_ } }
				  		= $OURS->{  $_ } ;
				} qw/webguiRoot bugzillaRoot skybillRoot/;

=back

All of the preload scripts, if any exist, are eval()'ed after the C<$spawn> is initialized with the values from:

=head2 Configuration File

C<fcgi_spawn.conf>, to be read from the configuration directory specified with C<-c> command line parameter, should contain the values of the L<FCGI::Spawn|FCGI::Spawn> object constructor, method "L<new|FCGI::Spawn/new>", if those need to differ from...

Syntax is: spaces and tabs at the begin of the line are ignored, the C<#> symbol before the rest means this line is ignored as a comment too, key and value are separated with the space(s) or tab(s) all on the same line, and if the value is multiple (...

Sample configuration file, C<fcgi_spawn.conf.sample>, is provided in the source distribution.

=head1 Typical CGI Applications with C<fcgi_spawn>

C<FCGI::Spawn>, and therefore C<fcgi_spawn>, are able to work in Unix and Cygwin environments, with 'properly' written CGI applications, which the most of the well-known CGI applications are. This means: no much assign of the global variables, incaps...

Care should be taken about file and database handles closing and networking sockets disconnection because the C<END{}> block of your Perl application is unlikely to be executed automatically, like it does in true CGI application. You should refer to ...

=head2 WebGUI.org

Till version 6.9 supported CGI mode, requires the 'date' system command to be present in the PATH. Fix this in preload script. You should C<preload_nonprepared> your C<index.pl> with the C<$spawn>'s ->L<callout|FCGI::Spawn/callout>, too. Demo is: L<h...

=head2 Skybill

Traffic accounting system was rewritten a bit, as you can see from L<http://skybill.sf.net>. It was ( and in many aspects is ) my old dummy code but it's to show that even that is able to be C<fcgi_spawn>-friendly. You may want to use the L</FCGI::Sp...

=head2 Bugzilla

Got to know satisfaction: this was probably a worst evil code ever seen. Despite it has no problems with mod_perl, that required many tricks to perform and here is the scoop:

=over

=item Many exit()s on the blocks

Requires the exit() to be redefined with C<-e> command line switch for C<fcgi_spawn>, and the C<CALLED_OUT> label to be crafted like it is already described here.

=item CGI.pm ancesting

Requires the both patches to be applied, on C<CGI.pm> amd C<Bugzilla/CGI.pm> .

=item Request caching

Bugzilla's own request cache cleans only if the mod_perl is used specifically. Same about the C<CALLED_OUT> here.

=item Environment cleaning

As an evil of L<Date::Manip|Date::Manip> ( I myself hate it too, since the C<DateTime.pm> infrastructure is much better ), and thus the WebGUI.org too, the Bugzilla can make your system commands unavailable from your applications on your PATH environ...

Also, in some cases the Bugzilla's CGI programs use to take $0 instead of $ENV{ SCRIPT_NAME } which makes the URLs generated pointless.

=back

Demo is located at:

=head1 BUGS And TODOs

L<http://bugs.vereshagin.org/product/FCGI%3A%3ASpawn>

Adequate reports are accepted.

=head1 Runtime Control

Daemon is supplied with POSIX signal handling: C<USR1> makes it to reopen the log file, and every other signal is passed as is to the actual L<FCGI::ProcManager|FCGI::ProcManager> process.

=head1 LICENSE

LGPL, as of the MANIFEST file in L<FCGI::Spawn|FCGI::Spawn>'s CPAN distribution. More info on fcgi_spawn at: L<http://fcgi-spawn.sf.net>.

=cut



( run in 1.434 second using v1.01-cache-2.11-cpan-71847e10f99 )