Add the .exe extension when appropriate to the clean target.
[catagits/fcgi2.git] / doc / fastcgi-prog-guide / ch4tcl.htm
CommitLineData
6791223e 1<html><head><title>FastCGI Programmer's Guide - Chapter 4, Developing FastCGI Applications in Tcl</title></head>
0198fd3c 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>
6791223e 9</a><a name="4835"></a>
0198fd3c 10This 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>
6791223e 11<a name="4943"></a>
0198fd3c 12The 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>
6791223e 13<a name="4221"></a>
0198fd3c 14In 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>
6791223e 15<a name="4222">
0198fd3c 16<h1> Getting Started</h1>
6791223e 17</a><a name="4223"></a>
0198fd3c 18The 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>
6791223e 19<a name="4226"></a>
0198fd3c 20Then, you have to divide FastCGI scripts into the following two sections:<p>
6791223e 21<ul><a name="4227"></a>
0198fd3c 22<li>Initialization section, which is executed only once.
6791223e 23<a name="4228"></a>
0198fd3c 24<li>Response loop section, which gets executed every time the FastCGI script gets called.
6791223e 25</ul><a name="4229"></a>
0198fd3c 26A response loop typically has the following format:<p>
6791223e 27<pre><a name="4923">
0198fd3c 28while {[FCGI_Accept] &gt;= 0 } {
29</a>
30<a name="4925">
31# body of response loop
32</a>
33<a name="4367">
34}
35</a>
6791223e 36</pre><a name="4233"></a>
0198fd3c 37The <code>FCGI_Accept</code> call returns 0 whenever a client requests the FastCGI script. Otherwise, the <code>FCGI_Accept</code> call returns -1. <p>
6791223e 38<a name="4853">
0198fd3c 39<h1> Example: TinyFastCGI</h1>
6791223e 40</a><a name="4343"></a>
0198fd3c 41Here is a simple example of a FastCGI application written in Tcl:<p>
6791223e 42<pre><a name="4344"></a>
0198fd3c 43#!fcgi-savvy-tcl
44
45set count 0
46
47# Response Loop
48while {[FCGI_Accept] &gt;= 0 } {
49 incr count
50 puts -nonewline "Content-type: text/html\r\n\r\n"
51 puts "&lt;title&gt;FastCGI Hello! (Tcl)&lt;/title&gt;"
52 puts "&lt;h1&gt;FastCGI Hello! (Tcl)&lt;/h1&gt;"
53 puts "Request number $count running on host &lt;i&gt;$env(SERVER_NAME)&lt;/i&gt;"
54}
55</pre>
56<p>
6791223e 57
0198fd3c 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>