1 package Catalyst::Engine::FastCGI;
4 use base 'Catalyst::Engine::CGI';
9 Catalyst::Engine::FastCGI - FastCGI Engine
13 This is the FastCGI engine.
15 =head1 OVERLOADED METHODS
17 This class overloads some methods from C<Catalyst::Engine::CGI>.
21 =item $self->run($c, $listen, { option => value, ... })
23 Starts the FastCGI server. If C<$listen> is set, then it specifies a
24 location to listen for FastCGI requests;
27 /path listen via Unix sockets on /path
28 :port listen via TCP on port on all interfaces
29 hostname:port listen via TCP on port bound to hostname
31 Options may also be specified;
34 leave_umask Set to 1 to disable setting umask to 0
36 nointr Do not allow the listener to be
38 nproc Specify a number of processes for
40 pidfile Specify a filename for the pid file
45 my ( $self, $class, $listen, $options ) = @_;
49 my $old_umask = umask;
50 unless ( $options->{leave_umask} ) {
53 $sock = FCGI::OpenSocket( $listen, 100 )
54 or die "failed to open FastCGI socket; $!";
55 unless ( $options->{leave_umask} ) {
61 or die "STDIN is not a socket; specify a listen location";
69 FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%env, $sock,
70 ( $options->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR ),
76 require FCGI::ProcManager;
77 $options->{nproc} ||= 1;
80 = FCGI::ProcManager->new( { n_processes => $options->{nproc} } );
82 if ( $options->{pidfile} ) {
83 $proc_manager->pm_write_pid_file( $options->{pidfile} );
86 $proc_manager->pm_manage();
89 while ( $request->Accept >= 0 ) {
90 $proc_manager && $proc_manager->pm_pre_dispatch();
91 $class->handle_request( env => \%env );
92 $proc_manager && $proc_manager->pm_pre_dispatch();
96 =item $self->write($c, $buffer)
101 my ( $self, $c, $buffer ) = @_;
103 unless ( $self->{_prepared_write} ) {
104 $self->prepare_write($c);
105 $self->{_prepared_write} = 1;
108 # FastCGI does not stream data properly if using 'print $handle',
109 # but a syswrite appears to work properly.
110 *STDOUT->syswrite($buffer);
118 =head1 WEB SERVER CONFIGURATIONS
120 =head2 Apache 1.x, 2.x
122 Apache requires the mod_fastcgi module. The following config will let Apache
123 control the running of your FastCGI processes.
125 # Launch the FastCGI processes
127 FastCgiServer /var/www/MyApp/script/myapp_fastcgi.pl -idle-timeout 300 -processes 5
130 ScriptAlias / /var/www/MyApp/script/myapp_fastcgi.pl/
133 You can also tell Apache to connect to an external FastCGI server:
135 # Start the external server (requires FCGI::ProcManager)
136 $ script/myapp_fastcgi.pl -l /tmp/myapp.socket -n 5
138 # Note that the path used in FastCgiExternalServer can be any path
140 FastCgiExternalServer /tmp/myapp_fastcgi.pl -socket /tmp/myapp.socket
143 ScriptAlias / /tmp/myapp_fastcgi.pl/
146 For more information on using FastCGI under Apache, visit
147 L<http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html>
151 This configuration was tested with Lighttpd 1.4.7.
153 server.document-root = "/var/www/MyApp/root"
158 "socket" => "/tmp/myapp.socket",
159 "check-local" => "disable",
160 "bin-path" => "/var/www/MyApp/script/myapp_fastcgi.pl",
168 You can also run your application at any non-root location.
178 You can also use an external server:
180 # Start the external server (requires FCGI::ProcManager)
181 $ script/myapp_fastcgi.pl -l /tmp/myapp.socket -n 5
183 server.document-root = "/var/www/MyApp/root"
188 "socket" => "/tmp/myapp.socket",
189 "check-local" => "disable"
194 For more information on using FastCGI under Lighttpd, visit
195 L<http://www.lighttpd.net/documentation/fastcgi.html>
199 It is possible to run Catalyst under IIS with FastCGI, but we do not
200 yet have detailed instructions.
204 L<Catalyst>, L<FCGI>.
208 Sebastian Riedel, <sri@cpan.org>
210 Christian Hansen, <ch@ngmedia.com>
212 Andy Grundman, <andy@hybridized.org>
216 This program is free software, you can redistribute it and/or modify it under
217 the same terms as Perl itself.