Quick and dirty FastCGI configuration using lighttpd

When you have problems with FastCGI, be they 'this doesn't run right' or 'this is running really slowly' problems, you need to isolate the problem. Is your web server FastCGI configuration screwed up, or is your Catalyst application broken?

Also, if you go to the mailing list and ask the question 'Why is my FastCGI application running so slowly?', with no supporting information, people will assume you're asking 'Why is Catalyst so bad? Couldn't you have written it properly?' and you'll get some more defensive comments than useful assistance.

The following configuration allows you to run lighttpd from the command line on your application as a test server. It's very simple - you probably wouldn't do this for a real application - but it's a known configuration with recognised limitations. Give it a try and see if you can give more information about what's going wrong. It uses a high port and should be run as a normal user - it's not intended to be started from your rc scripts. Copy the perl script below into your application root, and run it from the command line using the command

perl test.conf.pl <appname>

All requests will be routed via the Catalyst FastCGI script (including static ones) and you'll be able to see how it performs in a real environment with simultaneous requests working.

#!/usr/bin/perl
use strict; 
use warnings;

my $app=$ARGV[0];

use Cwd;    
my $pwd=Cwd::cwd();

my $filename='test.conf';
open my $f, '>', $filename or die "$filename: $!";

print $f <<EOF;
server.modules              = ("mod_fastcgi")

server.document-root        = "root"    

index-file.names            = ( "index.html", "index.htm", "default.htm" )  
# server.event-handler = "freebsd-kqueue" # needed on OS X

server.port                = 1500

fastcgi.server = (
    "" => ( 
        "app" => (
            "socket" => "$pwd/app.socket",
            "check-local" => "disable",
            "bin-path" => "$pwd/script/${app}_fastcgi.pl",
            "min-procs"    => 2, "max-procs"    => 5, "idle-timeout" => 20
        )                                                                           )
)                   
EOF             

close $f;   

exec 'lighttpd', '-D', '-f', 'test.conf';