1 <html><head><title></title></head>
4 <a href="cover.htm">[Top]</a> <a href="ch3perl.htm">[Prev]</a> <a href="apaman.htm">[Next]</a> <a href="ap_guida.htm">[Bottom]</a>
8 <center><h1>4 Developing FastCGI <br>Applications in Tcl</h1></center>
10 This chapter explains how to code FastCGI applications in Tcl. Prior to creating a FastCGI application, you must have a FastCGI-savvy version of the Tcl interpreter. Open Market develops Tcl binaries for popular platforms and makes them available with our developer's kit. <p>
12 The FastCGI-savvy binaries are extensions of standard Tcl, and are intended to replace your existing Tcl installation. There is no need to maintain two versions of Tcl: the version that we supply will work fine when invoked from a shell or a CGI program. There are also directions in the developer's kit for how to make your own FastCGI-savvy Tcl, if you need a version for some platform that we don't supply.<p>
14 In many cases, you can convert a Tcl script from CGI to FastCGI by adding a few lines of code to an existing script. For more complex scripts, you may also need to rearrange some existing code. <p>
16 <h1> Getting Started</h1>
18 The first line of any Tcl script typically specifies the pathname of the Tcl interpreter itself. You must specify the pathname of a FastCGI-savvy Tcl. <p>
20 Then, you have to divide FastCGI scripts into the following two sections:<p>
21 </a><ul><a name="4227">
22 <li>Initialization section, which is executed only once.
24 <li>Response loop section, which gets executed every time the FastCGI script gets called.
25 </a></ul><a name="4229">
26 A response loop typically has the following format:<p>
27 </a><pre><a name="4923">
28 while {[FCGI_Accept] >= 0 } {
31 # body of response loop
37 The <code>FCGI_Accept</code> call returns 0 whenever a client requests the FastCGI script. Otherwise, the <code>FCGI_Accept</code> call returns -1. <p>
39 <h1> Example: TinyFastCGI</h1>
41 Here is a simple example of a FastCGI application written in Tcl:<p>
42 </a><pre><a name="4344">
48 while {[FCGI_Accept] >= 0 } {
50 puts -nonewline "Content-type: text/html\r\n\r\n"
51 puts "<title>FastCGI Hello! (Tcl)</title>"
52 puts "<h1>FastCGI Hello! (Tcl)</h1>"
53 puts "Request number $count running on host <i>$env(SERVER_NAME)</i>"
60 <a href="cover.htm">[Top]</a> <a href="ch3perl.htm">[Prev]</a> <a href="apaman.htm">[Next]</a> <a href="ap_guida.htm">[Bottom]</a>
65 <!-- This file was created with Quadralay WebWorks Publisher 3.0.3 -->
67 <!-- For more information on how this document, and how the rest of -->
68 <!-- this server was created, email yourEmail@xyzcorp.com -->
70 <!-- Last updated: 04/15/96 08:00:19 -->