IIS 7 & IIS 8
Perl as FastCGI
Last post Jun 30, 2011 06:37 AM by naderelshehabi
Jun 19, 2011 08:40 AM|LINK
All over the internet are guides on how to run PHP via FastCGI, but almost no one is talking about Perl. Even those mentioning Perl are talking about ActivePerl. in Strawberry perl things are different.
I've managed to get Perl to run as CGI in IIS 7.5, but I wanted to either run it as ISAPI or as FastCGI. The Handler mapping of the CGI was "C:\perl\perl\bin\perl.exe %s". When I tried to replicate it in FastCGI I get "The
FastCGI executable could not be found" error!! PHP is working fine on my machine as FastCGI.
People say inActivePerl to use the PerlEx30.dll, which I couldn't find in Strawberry Perl. Any idea?
Jun 19, 2011 04:48 PM|LINK
Have you checked this
in IIS Net Forum. The post contains information that may help.
For the Handler mapping you have posted is not correct it should be "C:\Perl\bin\perl.exe" "%s%" %s .
You currently have "C:\Perl\perl\bin\perl.exe %s" and that will not work.
Check the post and links for more information.
windows server 2008
Jun 19, 2011 09:41 PM|LINK
Thank you for your reply,
Unfortunately the post talks about running Perl as CGI. What I'm trying is to run it as FastCGi. I already got it running as CGI. And strangely the "C:\Perl\perl\bin\perl.exe %s" does work by the way!
Do you know any sense in the %s syntax? What are the options?
Jun 20, 2011 01:41 AM|LINK
You can use all the guides in the previous post for Perl PHP Ruby and other Script Engines.
Just so you know you can have *.pl as FastCGI and *.cgi as Perl.exe and *.pls as Perlex30.dll your choice.
Check the Combination of this
http://learn.iis.net/page.aspx/697/configure-php-process-recycling-behavior/ guides for PHP it works for Perl also.
The syntax fo "%s%" %s is a macro to allow for two arguments to be passed to Perl.
The logic for Perl "%s%" %s comes from how C++ works with Main Entry Point.
Yes your current Handler and Mapping may appear to work but your loosing functionallity.
Question how did you do the install to get "C:\Perl\perl\bin\perl.exe" instead of the standard "C:\Perl\bin\perl.exe".
You may find it useful to create Enviroment Variable PERLHOME that has the perl.exe path.
Jun 20, 2011 07:35 AM|LINK
Thanks for your help. I still don't get the "%s%" %s syntax! Why the quotes and what are the available syntax? I mean is there a reference for this? Also PHP points only to php-cgi.exe without any arguments Also most people say it's
"%s" %s" not "%s%" %s, i.e. no second % after the first s.
Also all the posted guides talk about running perl as ISAPI while I'm trying to run it as
FastCGI. There is a difference. Using two Hello world pages; one in PHP as FastCGI and another in Perl as CGI rendered a response time of about 200 msec for the FastCGI and 800 msec for CGI. Why can't we run all scripting languages as FastCGI like
their site states? I know IIS FastCGI is MS implementation, but it should be the same?
The secret of my pain and the non standard "C:\Perl\perl\bin\perl.exe" path is that I'm using Strawberry Perl, not ActivePerl. That's why there is no PerlEx30.dll like all the guides say!
One note I'll be trying later is that I'm running Windows x64, FastCGI x64, and Perl is x86! Could that be it? All I want is how to debug this error?
Thanks for all your help.
Jun 20, 2011 09:13 AM|LINK
You have a number of things that will be different for Which Perl you install and
how you configure and methods possible.
What to install or not install based on type of use and expectations:
You will save time and confusion by getting the Active State Perl Windows Installer for Windows intel X86.
The Active State Perl Community Edition installer is Freeware and has the ISAPI dll's built for Windows.
You do not need the Perl X64 version while running Windows amd X64 the Perl being X86 is not a problem.
To begin with Strawberry Perl is not built with the ISAPI extensions and will only
have CGI operations and the Handler is *.pl and PATH to Perl.exe with Verbs Get,Host,Post and
Restrictions for File and use as Script for Actions so that is the IIS Server simple settings.
The Strawberry Perl is a replacement for the Perl.org Distribution with somw bug fixes and extra libraries.
Why the parameters are and what use is this and common conventions:
The reason for the quotes is problems with Windows and PATH's and order of parsing parameters for Perl.
The Perl uses two macros %s% and %s to receive the first and second parameters which is C++ convention
which Perl expects for normal operation.
If you have only the first parameter Perl will appear to work but is missing functionallity.
If you check the Active State Documentation the Perl uses <% and code inside %> for operations
and matches the conventions for Asp which uses <% and code inside %> for Request and Response
and server side code.
The Active State Perl also adds Registery Entries for passing of parameters.
The macros allows you to escape the <% characters %> in the correct order and pass the values.
How to use FastCGI or ISAPI or CGI and have Handler and Mappings:
You can have Handler and a mapping for each type *.pl *.cgi *.pls and use CGI Perl Script or Perlex30.dll or FastCGI
the requirement is have a unique Name and Use a Module with that Mapping.
Yes you may find differences for Timing using FastCGI or ISAPI vs Script Engine Native.
The advantage of using FastCGI is it provides additional Control operations for Code and Script Execution.
There are differences for how ISAPI for Active Perl and FastCGI were built and functions.
You can use the FastCGI for all the scripting engines provided you use unique Name and Path to Script Engine.
The FastCGI by Microsoft and other ISAPI modules have differences for implementation and the Compilers use.
Suggestions and Options:
I suggest you check the link and guide at Web Panel web site and install the Active State Perl
and start with a Handler and mapping *.cgi and "C:\Perl\bin\perl.exe" "%s%" %s and Name CGI Perl.
Then using the guides create a FastCGI
Handler and Mapping for *.pl and FastCGI and "C:\Perl\bin\perl.exe" %s% %s and Name FastCGI Perl.
The FastCGI Handler Mapping you can use modified versions of the PHP variables to identify them for Perl.
The FastCGI Handler Mapping also allows you to set the max number of instances and recycling.
Final note: If you get gateway errors or execution errors while running scripts for Perl or PHP
you need to send Headers as first item that gets sent to IIS Server.
The expected format for the Header is "Content: type/text\n"; or Content: type/html\n"; as given by the http 1.1 RFC
conventions and standards.
The configuration for Perl can be dauting since the Web Does contain old guides and mixtures of Systems being used.
Hope I this helps,
Jun 20, 2011 10:49 AM|LINK
Your reply was very informative. I couldn't get it to work though -changing the %s to "%s%" %s didn't have any effect-, yet at least I got more light on the matter. Perl and Python both working fine on IIS7.5 as CGI, yet as FastCGI I get the following error
in the failed request log:
The reason I chose Strawberry Perl is that it's free. Production license for ActivePerl is $1000 per server -At the time of this writing of course, and this info may be inaccurate. Any reader should refer to their site for accurate price-.
I marked your reply as an answer already. If you have any more thoughts about this mystery, I'd be extremely grateful. Otherwise, thanks a lot for your effort.
Jun 20, 2011 11:00 AM|LINK
Yes, The Active State Perl Commercial Version is one thing.
You also have the Community Edition which is free
If you get the FastCGI Exit problems check that the Visual Studio runtimes are installed
and the FastCGI recycle settings are correct.
Check this guide
http://learn.iis.net/page.aspx/697/configure-php-process-recycling-behavior/ and item 4
you set the Environment and Requests values.
This is where you can define PERLHOME and set to C:\Perl\bin.
Jun 20, 2011 11:54 AM|LINK
Environment variable set! Recycling settings are correct.. No change! Same error.
Jun 20, 2011 12:12 PM|LINK
Check this post http://forums.iis.net/t/1178484.aspx for FastCGI Active Perl and Bugzilla
look at the ISAPI and CGI restrictions Picture and matching pane in IIS Manager it is possible to have duplicates.
The duplicates can cause errors and prevent you modifying the Path and Perl settings.