1 package Catalyst::Engine::FastCGI;
4 use base 'Catalyst::Engine::CGI';
6 die "Please install FCGI\n" if $@;
10 Catalyst::Engine::FastCGI - FastCGI Engine
14 This is the FastCGI engine.
16 =head1 OVERLOADED METHODS
18 This class overloads some methods from C<Catalyst::Engine::CGI>.
22 =item $self->run($c, $listen, { option => value, ... })
24 Starts the FastCGI server. If C<$listen> is set, then it specifies a
25 location to listen for FastCGI requests;
28 /path listen via Unix sockets on /path
29 :port listen via TCP on port on all interfaces
30 hostname:port listen via TCP on port bound to hostname
32 Options may also be specified;
35 leave_umask Set to 1 to disable setting umask to 0
37 nointr Do not allow the listener to be
39 nproc Specify a number of processes for
41 pidfile Specify a filename for the pid file
46 my ( $self, $class, $listen, $options ) = @_;
50 my $old_umask = umask;
51 unless ( $options->{leave_umask} ) {
54 $sock = FCGI::OpenSocket( $listen, 100 )
55 or die "failed to open FastCGI socket; $!";
56 unless ( $options->{leave_umask} ) {
62 or die "STDIN is not a socket; specify a listen location";
70 FCGI::Request( \*STDIN, \*STDOUT, \*STDERR, \%env, $sock,
71 ( $options->{nointr} ? 0 : &FCGI::FAIL_ACCEPT_ON_INTR ),
77 require FCGI::ProcManager;
78 $options->{nproc} ||= 1;
81 FCGI::ProcManager->new( { n_processes => $options->{nproc} } );
83 if ( $options->{pidfile} ) {
84 $proc_manager->pm_write_pid_file( $options->{pidfile} );
87 $proc_manager->pm_manage();
90 while ( $request->Accept >= 0 ) {
91 $proc_manager && $proc_manager->pm_pre_dispatch();
92 $class->handle_request( env => \%env );
93 $proc_manager && $proc_manager->pm_pre_dispatch();
97 =item $self->write($c, $buffer)
102 my ( $self, $c, $buffer ) = @_;
104 unless ( $self->{_prepared_write} ) {
105 $self->prepare_write($c);
106 $self->{_prepared_write} = 1;
109 # FastCGI does not stream data properly if using 'print $handle',
110 # but a syswrite appears to work properly.
111 *STDOUT->syswrite($buffer);
119 =head1 WEB SERVER CONFIGURATIONS
121 =head2 Apache 1.x, 2.x
123 Apache requires the mod_fastcgi module. The following config will let Apache
124 control the running of your FastCGI processes.
126 # Launch the FastCGI processes
128 FastCgiServer /var/www/MyApp/script/myapp_fastcgi.pl -idle-timeout 300 -processes 5
131 ScriptAlias / /var/www/MyApp/script/myapp_fastcgi.pl/
134 You can also tell Apache to connect to an external FastCGI server:
136 # Start the external server (requires FCGI::ProcManager)
137 $ script/myapp_fastcgi.pl -l /tmp/myapp.socket -n 5
139 # Note that the path used in FastCgiExternalServer can be any path
141 FastCgiExternalServer /tmp/myapp_fastcgi.pl -socket /tmp/myapp.socket
144 ScriptAlias / /tmp/myapp_fastcgi.pl/
147 For more information on using FastCGI under Apache, visit
148 L<http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html>
152 This configuration was tested with Lighttpd 1.4.7.
154 server.document-root = "/var/www/MyApp/root"
159 "socket" => "/tmp/myapp.socket",
160 "check-local" => "disable",
161 "bin-path" => "/var/www/MyApp/script/myapp_fastcgi.pl",
169 You can also run your application at any non-root location.
179 You can also use an external server:
181 # Start the external server (requires FCGI::ProcManager)
182 $ script/myapp_fastcgi.pl -l /tmp/myapp.socket -n 5
184 server.document-root = "/var/www/MyApp/root"
189 "socket" => "/tmp/myapp.socket",
190 "check-local" => "disable"
195 For more information on using FastCGI under Lighttpd, visit
196 L<http://www.lighttpd.net/documentation/fastcgi.html>
200 It is possible to run Catalyst under IIS with FastCGI, but we do not
201 yet have detailed instructions.
205 L<Catalyst>, L<FCGI>.
209 Sebastian Riedel, <sri@cpan.org>
211 Christian Hansen, <ch@ngmedia.com>
213 Andy Grundman, <andy@hybridized.org>
217 This program is free software, you can redistribute it and/or modify it under
218 the same terms as Perl itself.