|
Running Perl Programs with IIS
This chapter describes:
- How to configure IIS 5.0 to run Perl programs.
- How to use perlis.dll instead of perl.exe with IIS.
- Performance comparison among Perl, JSP, and ASP technologies.
Configuring IIS 5.0 for Perl Programs
One of most commonly used areas of Perl language is Web server side application.
If your application is written in Perl, and want to run it through a Web
browser request, you must configure your Web server to be able to run the application.
On a Unix system, this is very easy. But on a Windows system, you need
to do some experiments.
I had Internet Information Services (IIS) 5.0 Web server running on my Windows 2000 system,
and ActivePerl v5.6.1 installed
on c:\perl. Here is what I did to run Perl programs with IIS.
1. Made a new sub directory in the default Web server home directory,
c:\Inetpub\wwwroot\cgi-bin.
2. Copied my hello.pl to that new directory, c:\Inetpub\wwwroot\cgi-bin\hello.pl.
print "Hello world!\n";
3. Ran "Internet Information Services (IIS)", selected "Default Web Site"
under localhost, clicked the stop icon, then clicked the start icon. This
was to restart the IIS server, so the new sub directory and the new Perl program
can be picked up by the server.
4. On IIS, selected the cgi-bin directory, and right mouse clicked to
view the properties window. On the Directory tab, saw Read and Write were
checked, and Execution Permissions had "Script only".
5. Ran Internet Explorer (IE) with http:\\localhost\cgi-bin\hello.pl,
a download windows came up asking me to save hellp.pl. Not too bad,
my cgi-bin sub directory and hello.pl was reachable!
6. On IIS, selected "Default Web Sites", then right mouse clicked to
view the properties window. On the "Home Directory" tab, clicked
the "Configuration" button. Here I had to add a new entry into the
Application Mappings:
Executable: c:\perl\bin\perl.exe %s
Extension: .pl
Verbs: All verbs
Script Engine: Checked
7. Tried again with IE on http:\\localhost\cgi-bin\hello.pl, and got the following
output. Much better now, hello.pl got executed.
CGI Error
The specified CGI application misbehaved by not returning
a complete set of HTTP headers. The headers it did return are:
Hello world!
8. Changed hello.pl to helloHttp.pl:
print "Content-Type: text/html\n\n";
print "<html><body>\n";
print "Hello world!\n";
print "</html></body>\n";
<html><body>
<% out.println("Hello world!"); %>
</body></html>
9. Finally, I got the perfect output with IE on http:\\localhost\cgi-bin\helloHttp.pl
Hello world!
Excellent! From now on, any files with .pl in the cgi-bin directory
will be executed by perl.exe.
By the way,
you could also follow the instructions provided by ActivePerl at:
c:\Perl\html\faq\Windows\ActivePerl-Winfaq6.html
perl.exe vs. perlis.dll
Instead of using perl.exe, you could also use perlis.dll to run your Perl programs
through IIS. perlis.dll is the DLL of Perl for ISAPI.
The advantage of using PerlIS.dll is that IIS will only need to load
PerlIS.dll into memory once, therefore much quicker to run the next Perl program
if requested.
To try Perl for ISAPI, I decided to
configure IIS to run *.plx files in cgi-bin with perlis.dll. I repeated
the steps
described in the previous section to add another entry into the Application
Mappings:
Executable: c:\perl\bin\perlis.dll
Extension: .plx
Verbs: All verbs
Script Engine: Checked
Then I changed Changed helloHttp.pl to helloHttp.plx:
print "Content-Type: text/html\n\n";
print "<html><body>\n";
print "Hello world!\n";
print "</html></body>\n";
Checked with IE on http:\\localhost\cgi-bin\helloHttp.plx, and got the output correctly.
To compare the performance difference between perl.exe and perlis.dll, I used
the following Java program. This program is doing a single HTTP request to
a specified Web page, and repeating this for many times.
/**
* HttpResponseTest.java
* Copyright (c) 2002 by Dr. Herong Yang. All rights reserved.
*/
import java.io.*;
import java.net.*;
public class HttpResponseTest {
public static void main(String[] args) {
int numberOfTests = 1;
if (args.length > 0) numberOfTests
= Integer.valueOf(args[0]).intValue();
long t1 = System.currentTimeMillis();
String result = "";
for (int nTest=1; nTest<=numberOfTests; nTest++) {
result = test(args);
}
long t2 = System.currentTimeMillis();
long t = t2 - t1;
PrintStream out = System.out;
out.println("Performace Information:");
out.println(" Number of tests = " + numberOfTests);
out.println(" Time = " + (t/1000) + " seconds.");
out.println("Rerulst of Last Test:");
out.println(result);
}
public static String test(String[] args) {
String path = "/index.html";
int port = 80;
String host = "localhost";
if (args.length > 1) path = args[1];
if (args.length > 2) port
= Integer.valueOf(args[2]).intValue();
if (args.length > 3) host = args[3];
String result = "";
try {
Socket c = new Socket(host,port);
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(
c.getOutputStream()));
BufferedReader r = new BufferedReader(new InputStreamReader(
c.getInputStream()));
String m = "GET "+path;
w.write(m,0,m.length());
w.newLine();
w.flush();
while ((m=r.readLine())!= null) {
result = result + m + "\n";
}
w.close();
r.close();
c.close();
} catch (IOException e) {
System.err.println(e.toString());
}
return result;
}
}
Here is the output my first test:
\j2sdk1.4.1_01\bin\java -cp . HttpResponseTest 1 /cgi-bin/helloHttp.pl
Performace Information:
Number of tests = 1
Time = 0 seconds.
Rerulst of Last Test:
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.0
Date: Mon, 23 Dec 2002 19:39:09 GMT
Content-Type: text/html
<html><body>
Hello world!
</body></html>
I repeated the tests by changing the controlling parameters.
The following table shows the results comparing with similar tests I did
with other technologies:
Number Debug Time
Cases of Tests Mode (Sec) Note
1. 1000 No 2 Static text with IIS 5.0
2. 2000 No 4 Static text with IIS 5.0
3. 1000 No 6 ASP page with IIS 5.0
4. 2000 No 11 ASP page with IIS 5.0
5. 1000 ? 7 Static text with Tomcat 4.1.18
6. 2000 ? 15 Static text with Tomcat 4.1.18
7. 1000 ? 8 JSP page with Tomcat 4.1.18
8. 2000 ? 16 JSP page with Tomcat 4.1.18
9. 1000 ? 25 perl.exe 5.6.1 with IIS 5.0
10. 2000 ? 47 perl.exe 5.6.1 with IIS 5.0
11. 1000 ? 12 perlis.dll 5.6.1 with IIS 5.0
12. 2000 ? 24 perlis.dll 5.6.1 with IIS 5.0
Conclusion:
- Obviously, perl.exe is 2 times slower than perlis.dll.
So I changed the configuration on IIS to map *.pl files to perlis.dll.
- Perl is slower than JSP and ASP.
|