Perl, IIS and FastCGI


M

mab2001

I have a FastCGI Perl application that runs well with the Apache and
the FastCGI module on Windows and Linux. Recently though, I needed to
get it running with IIS (version 6) and so I turned to the FastCGI
ISAPI DLL written by Shane Caraveo and now part of the PHP source tree
(http://cvs.php.net/viewcvs.cgi/fastcgi-isapi/). I had some
difficulties getting my app working like it does with the Apache
FastCGI module and so I though I'd share my experiences.

So my goal was to get the ISAPI DLL to create CGI servers dynamically
based on the requested URL as can be done with the Apache module. In
the end this required a code change to the ISAPI DLL. The patches are
below. (I should submit these to the PHP project.) Basically I had two
problems: preserving Perl's arguments when running dynamic servers and
getting the ISAPI DLL to run the dynamic server as a FastCGI responder
instead of a filter. The changes I made allowed/fixed these.

I then created the following keys in the registry:

HKEY_LOCAL_MACHINE\SOFTWARE\FASTCGI\.pl

In this key, I added the following values:

AppPath REG_SZ c:\tools\perl\5.6.1\bin\MSWin32-x86\perl.exe
Args REG_SZ -T
BindPath REG_SZ

Note that the value of Args is "-T " (with a space). BindPath is empty.
(Perhaps it's not necessary.)
From that point, configuration was just as it is with PHP except that
for the website I associated the DLL with the extension .pl instead of
..php. See instructions here for example:

http://www.simongibson.com/intranet/php2003/

Other obstacles I encountered not specific to FastCGI and Perl were
ensuring that the account used to run the CGI scripts had all the
proper permissions and that all the dependent DLLs for the FastCGI
ISAPI DLL were on the machine. Here's a useful tool to help with that:

http://www.dependencywalker.com/

Anyway, I hope this helps save someone else some time.

Mike


--- FCGIProcMgr.cpp Thu Apr 27 14:46:38 2006
+++ FCGIProcMgr.cpp.new Thu Apr 27 14:45:54 2006
@@ -388,7 +388,10 @@
proc->incServers = parent->incServers;
proc->maxServers = parent->maxServers;
proc->timeout = parent->timeout;
- if (path) strncpy(proc->args, path, sizeof(proc->args)-1);
+ proc->isFilter = parent->isFilter;
+ *( proc->args ) = 0;
+ if (parent->args) strncpy(proc->args, parent->args,
sizeof(proc->args)-1);
+ if (path) strncpy(proc->args + strlen (proc->args), path,
sizeof(proc->args)-1 - strlen (proc->args) );
strncpy(proc->bindPath, bindpath, sizeof(proc->bindPath)-1);
if (dwServerImpersonate) {
proc->env.putEnv("_FCGI_NTAUTH_IMPERSONATE_=1");

And I also needed this change to compile it on my machine:

--- fcgi_server.h Thu Apr 27 14:46:38 2006
+++ fcgi_server.h.new Thu Apr 27 14:43:46 2006
@@ -25,6 +25,10 @@
#define FCGI_SERVER_VERSION "2.2.2 0.5.2 beta"
#define FCGI_ENVIRON_VER "FCGI_SERVER_VERSION=" FCGI_SERVER_VERSION

+#if !defined (INVALID_FILE_ATTRIBUTES)
+#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
+#endif
+
extern void InitiateServers(char *szExtension);
extern void CheckServers(char *szExtension);
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top