We have an existing Perl application that supports mod_perl. However, our new host (Dreamhost) does not suppport mod_perl, only FastCGI; thus necessitating the port.
The existing code does not use any Apache specific stuff and is just normal Perl code written in way that’s acceptable to mod_perl.
Reading the documentation and online tutorials, it appears that adding FastCGI support involves wrapping existing code inside a specific kind of loop. Below are the most commonly given skeleton code:
A. Using FCGI
use FCGI; while (FCGI::accept >= 0) { #Run existing code. }
B. Using CGI::Fast
use CGI::Fast while (my $cgi = CGI::Fast->new()) { #Run existing code. }
Sub-Questions:
- Are methods A and B equivalent ways to add FastCGI support?
- If A and B are different, what then are the pros and cons of using one over the other?
- Are there any best practices or gotchas one should know about when porting from
mod_perlto FastCGI?
Thanks.
Generically speaking, a FastCGI application is very similar to CGI. The major difference is that you can take advantage of the fact that your process is able to be persistent. You can leverage that to gain speed advantages in your application—for example, you can cache database data in your running process. Essentially, you’re changing your application into its own application server, running behind a FastCGI gateway provided by the Web server.
The idea is to figure out how to make your application’s means of processing applicable to a FastCGI gateway. Do you use any mod-perl specific functionality? If so, move away from that. If not, then just start working on talking via FastCGI. You’ve an advantage in that there are FastCGI interfaces available for Perl. I assume that you’re using some sort of a version control system, so just make a branch that is for porting to FastCGI. Then, just start thinking about POST and PUT as reading from standard input and your application’s responses as writing to standard output.
You may want to also just read through a library that implements a FastCGI interface for an application. You can find some of those at fastcgi.com. That might help for you to understand what your application is going to be doing differently in relation to what it is doing currently.
Good luck!