TWiKi and FastCGI
Given the recent slashdotting my site received, my ISP asked me to look into getting the ‘view’ script used to render pages on my site to run with FastCGI. It’s proving to be more difficult than I expected. I am able to have it run for a period of time, but it seems the script “wedges” every so often, and just flat out refuses to run.
FastCGI is a good idea because it essentially starts up the application one time to service requests and keeps the application in memory. However, I can’t seem to get the “view” script to run for extended periods of time without eventually crapping out. Maybe I need to occasionally terminate and restart the script to assist in that. I don’t know.
Because the site uses the CGI libraries, I was under the impression that I would have to use CGI::Fast instead. Attempts at using this library were, shall we say, unsuccessful. I believe I have gotten this to work correctly now using the FCGI method and a little redirection, except for it needing the occasional kick once in a while. Porting all the scripts takes a little bit of time, and I only really need it on the “view” script, the script everyone uses.
Most perl scripts look like this:
&do_initialization(); # Where you do stuff like 'use' statements
&do_stuff();
Now the script looks something like:
use FCGI;
&do_initialization();
my $request = FCGI::Request();
while ( $request->Accept() >= 0 ) {
&do_stuff();
$request->Flush();
$request->Finish();
}
One other problem: all of the “scripts” for my site end in .pl, which get treated as a normal CGI, meaning it won’t get treated as a fastcgi script. It’s non-trivial to get TWiki to use .pl for all other scripts, but use, say, .fpl for the view script. In this case, I use a redirect to direct views at .pl to .fpl.
Of course, it’s all moot if I can’t get the script to ‘stay running’ properly.