Commit | Line | Data |
0198fd3c |
1 | <html><head><title></title></head> |
2 | <body bgcolor=#ffffff> |
3 | |
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> |
5 | <hr><br> |
6 | |
7 | <a name="3659"> |
8 | <center><h1>4 Developing FastCGI <br>Applications in Tcl</h1></center> |
9 | </a><a name="4835"> |
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> |
11 | </a><a name="4943"> |
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> |
13 | </a><a name="4221"> |
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> |
15 | </a><a name="4222"> |
16 | <h1> Getting Started</h1> |
17 | </a><a name="4223"> |
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> |
19 | </a><a name="4226"> |
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. |
23 | </a><a name="4228"> |
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 } { |
29 | </a> |
30 | <a name="4925"> |
31 | # body of response loop |
32 | </a> |
33 | <a name="4367"> |
34 | } |
35 | </a> |
36 | </pre><a name="4233"> |
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> |
38 | </a><a name="4853"> |
39 | <h1> Example: TinyFastCGI</h1> |
40 | </a><a name="4343"> |
41 | Here is a simple example of a FastCGI application written in Tcl:<p> |
42 | </a><pre><a name="4344"> |
43 | #!fcgi-savvy-tcl |
44 | |
45 | set count 0 |
46 | |
47 | # Response Loop |
48 | while {[FCGI_Accept] >= 0 } { |
49 | incr count |
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>" |
54 | } |
55 | </pre> |
56 | <p> |
57 | </a> |
58 | <hr><br> |
59 | |
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> |
61 | <hr><br> |
62 | |
63 | |
64 | |
65 | <!-- This file was created with Quadralay WebWorks Publisher 3.0.3 --> |
66 | <!-- --> |
67 | <!-- For more information on how this document, and how the rest of --> |
68 | <!-- this server was created, email yourEmail@xyzcorp.com --> |
69 | <!-- --> |
70 | <!-- Last updated: 04/15/96 08:00:19 --> |
71 | |
72 | </body> |
73 | </html> |