Commit | Line | Data |
852467e2 |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> |
2 | <HTML> |
3 | <HEAD> |
4 | <TITLE> |
5 | FastCGI Programmer's Guide - Chapter 4, Developing FastCGI Applications in Tcl |
6 | </TITLE> |
7 | <STYLE TYPE="text/css"> |
8 | body { |
9 | background-color: #ffffff; |
10 | } |
11 | li.c2 {list-style: none} |
12 | div.c1 {text-align: center} |
13 | </STYLE> |
14 | </HEAD> |
15 | <BODY> |
16 | <A HREF="cover.htm">[Top]</A> <A HREF="ch3perl.htm">[Prev]</A> <A HREF="apaman.htm">[Next]</A> <A HREF= |
17 | "ap_guida.htm">[Bottom]</A> |
18 | <HR> |
19 | <BR> |
20 | <A NAME="3659"></A> |
21 | <DIV CLASS="c1"> |
22 | <H1> |
23 | 4 Developing FastCGI<BR> |
24 | Applications in Tcl |
25 | </H1> |
26 | </DIV> |
27 | <A NAME="4835"></A> |
28 | <P> |
29 | This chapter explains how to code FastCGI applications in Tcl. Prior to creating a FastCGI application, you |
30 | must have a FastCGI-savvy version of the Tcl interpreter. Open Market develops Tcl binaries for popular |
31 | platforms and makes them available with our developer's kit. |
32 | </P> |
33 | <P> |
34 | <A NAME="4943"></A> The FastCGI-savvy binaries are extensions of standard Tcl, and are intended to replace |
35 | your existing Tcl installation. There is no need to maintain two versions of Tcl: the version that we supply |
36 | will work fine when invoked from a shell or a CGI program. There are also directions in the developer's |
37 | kit for how to make your own FastCGI-savvy Tcl, if you need a version for some platform that we don't |
38 | supply. |
39 | </P> |
40 | <P> |
41 | <A NAME="4221"></A> In many cases, you can convert a Tcl script from CGI to FastCGI by adding a few lines of |
42 | code to an existing script. For more complex scripts, you may also need to rearrange some existing code. |
43 | </P> |
44 | <BR> |
45 | <BR> |
46 | <H1> |
47 | Getting Started |
48 | </H1> |
49 | <A NAME="4223"></A> |
50 | <P> |
51 | The first line of any Tcl script typically specifies the pathname of the Tcl interpreter itself. You must |
52 | specify the pathname of a FastCGI-savvy Tcl. |
53 | </P> |
54 | <P> |
55 | <A NAME="4226"></A> Then, you have to divide FastCGI scripts into the following two sections: |
56 | </P> |
57 | <BR> |
58 | <BR> |
59 | <UL> |
60 | <LI CLASS="c2"> |
61 | <A NAME="4227"></A> |
62 | </LI> |
63 | <LI> |
64 | Initialization section, which is executed only once. <A NAME="4228"></A> |
65 | </LI> |
66 | <LI> |
67 | Response loop section, which gets executed every time the FastCGI script gets called. |
68 | </LI> |
69 | </UL> |
70 | <A NAME="4229"></A> |
71 | <P> |
72 | A response loop typically has the following format: |
73 | </P> |
74 | <BR> |
75 | <BR> |
76 | <PRE> |
77 | <A NAME="4923">while {[FCGI_Accept] >= 0 } { |
78 | </A> |
79 | <A NAME="4925"># body of response loop |
80 | </A> |
81 | <A NAME="4367">} |
82 | </A> |
83 | </PRE> |
84 | <A NAME="4233"></A> |
85 | <P> |
86 | The <CODE>FCGI_Accept</CODE> call returns 0 whenever a client requests the FastCGI script. Otherwise, the |
87 | <CODE>FCGI_Accept</CODE> call returns -1. |
88 | </P> |
89 | <BR> |
90 | <BR> |
91 | <H1> |
92 | Example: TinyFastCGI |
93 | </H1> |
94 | <A NAME="4343"></A> |
95 | <P> |
96 | Here is a simple example of a FastCGI application written in Tcl: |
97 | </P> |
98 | <BR> |
99 | <BR> |
100 | <PRE> |
101 | <A NAME="4344"></A> |
102 | #!fcgi-savvy-tcl |
103 | |
104 | set count 0 |
105 | |
106 | # Response Loop |
107 | while {[FCGI_Accept] >= 0 } { |
108 | incr count |
109 | puts -nonewline "Content-type: text/html\r\n\r\n" |
110 | puts "<title>FastCGI Hello! (Tcl)</title>" |
111 | puts "<h1>FastCGI Hello! (Tcl)</h1>" |
112 | puts "Request number $count running on host <i>$env(SERVER_NAME)</i>" |
113 | } |
114 | </PRE> |
115 | <P> |
116 | </P> |
117 | <HR> |
118 | <BR> |
119 | <A HREF="cover.htm">[Top]</A> <A HREF="ch3perl.htm">[Prev]</A> <A HREF="apaman.htm">[Next]</A> <A HREF= |
120 | "ap_guida.htm">[Bottom]</A> |
121 | <HR> |
122 | <BR> |
123 | <!-- This file was created with Quadralay WebWorks Publisher 3.0.3 --> |
124 | <!-- --> |
125 | <!-- For more information on how this document, and how the rest of --> |
126 | <!-- this server was created, email yourEmail@xyzcorp.com --> |
127 | <!-- --> |
128 | <!-- Last updated: 04/15/96 08:00:19 --> |
129 | </BODY> |
130 | </HTML> |
131 | |