[cgiapp] CGI::App FastCGI and Forking Behavior

Thomas Krichel krichel at openlib.org
Thu Jan 8 13:11:24 EST 2015


  Justin J writes

> I don't know what I should worry about, or what has been figure out. 

  Well, for what it's worth, here is what I have done when migrationg a project
  to CGI::App with, hopefully, fastCGI under suxexec. I run apache mod_fcgid.
  It's a module I can much recommend, it is rock solid.  

  To illustrate, my application is ernad. 

  In /etc/apache2/sites-available/ernad.repec.org 

RewriteEngine on
RewriteRule ^/$ /cgi-bin/nep_ernad.fcgi$1 [L]

ScriptAlias /cgi-bin /var/www/ernad/cgi-bin
<directory /var/www/ernad/cgi-bin>
  AddHandler fcgid-script .fcgi
  AllowOverride None
  Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
  Order allow,deny
  Allow from all
</directory>

<location />
  AddHandler fcgid-script .fcgi
  Options ExecCGI FollowSymLinks
</location>

  Here is /var/www/ernad/cgi-bin/nep_ernad.fcgi 

#!/usr/bin/perl -w

use lib qw(/home/ernad/ernad/perl/);
use CGI::Fast qw/-utf8/;

use Ernad::Erimp;
use Ernad::Index;

my $impna='nep';

our $e=Ernad::Erimp->new({'impna'=>$impna}) or die;

while (my $q = new CGI::Fast) {
  my $app = new Ernad::Index(QUERY => $q); 
  $app->run();
}

  This approach seems to work fine. Apache fires up a new fcgi daemon
  when none is running and a request comes along. I don't need 
  a startup script for the fcgi daemon. 

  My application is supposed to create an application object, an Erimp,
  when it starts. This loads the stylesheets, so they are compiled 
  when a request arrives. The other day I changed the stylesheet without
  the killing---thus restarting---the daemon, and it showed the results
  of the changed sheet, which it should not have done, so I need to 
  look into this more, but as far I understand, this is the sort
  of setup you need to run CGI::App as FastCGI without much trouble.

-- 

  Cheers,

  Thomas Krichel                  http://openlib.org/home/krichel
                                              skype:thomaskrichel


More information about the cgiapp mailing list