define HAVE_IOSTREAM_WITHASSIGN_STREAMBUF
[catagits/fcgi2.git] / doc / fastcgi-prog-guide / ch1intro.htm
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">\r
2 <HTML>\r
3    <HEAD>\r
4       <TITLE>\r
5          FastCGI Programmer&#39;s Guide - Chapter 1, The Fast Common Gateway Interface\r
6       </TITLE>\r
7 <STYLE TYPE="text/css">\r
8  body {\r
9   background-color: #ffffff;\r
10  }\r
11  li.c2 {list-style: none}\r
12  div.c1 {text-align: center}\r
13 </STYLE>\r
14    </HEAD>\r
15    <BODY>\r
16       <A HREF="cover.htm">[Top]</A> <A HREF="ap_guide.htm">[Prev]</A> <A HREF="ch2c.htm">[Next]</A> <A HREF=\r
17       "ap_guida.htm">[Bottom]</A> \r
18       <HR>\r
19       <BR>\r
20        <A NAME="9432"></A>\r
21       <DIV CLASS="c1">\r
22          <H1>\r
23             1 The Fast Common<BR>\r
24             Gateway Interface\r
25          </H1>\r
26       </DIV>\r
27       <A NAME="7982"></A>\r
28       <P>\r
29          The Fast Common Gateway Interface (FastCGI) is an enhancement to the existing CGI (Common Gateway Interface),\r
30          which is a standard for interfacing external applications with Web servers.\r
31       </P>\r
32       <P>\r
33          <A NAME="8373"></A> FastCGI is a proposed open standard and we expect both free and commercial Web servers to\r
34          support it. FastCGI is included in Open Market WebServer and Secure WebServer, versions 2.0 and greater.\r
35       </P>\r
36       <BR>\r
37       <BR>\r
38       <H1>\r
39          Advantages of FastCGI\r
40       </H1>\r
41       <A NAME="8369"></A>\r
42       <P>\r
43          FastCGI extends and enhances the CGI model in several ways:\r
44       </P>\r
45       <BR>\r
46       <BR>\r
47       <UL>\r
48          <LI CLASS="c2">\r
49             <A NAME="7832"></A>\r
50          </LI>\r
51          <LI>\r
52             FastCGI enables applications to persist between client requests, eliminating application start up overhead\r
53             and allowing the application to maintain state between client calls. <A NAME="7995"></A>\r
54          </LI>\r
55          <LI>\r
56             FastCGI enables applications to reside on remote systems (rather than having to reside on the same system\r
57             as the Web server) <A NAME="7997"></A>\r
58          </LI>\r
59          <LI>\r
60             FastCGI enables additional flexibility in application functionality, with explicit support for applications\r
61             that do client authentication and filtering of input.\r
62          </LI>\r
63       </UL>\r
64       <H2>\r
65          Long-lived Applications\r
66       </H2>\r
67       <A NAME="8458"></A>\r
68       <P>\r
69          CGI applications are ephemeral and short-lived: each time a client requests a CGI application, the server asks\r
70          the operating system to spawn a new CGI process. After the CGI process satisfies the request, the server kills\r
71          it. The server spawns and subsequently kills a new process for each client request.\r
72       </P>\r
73       <P>\r
74          <A NAME="8459"></A> FastCGI applications are long-lived, and can persist between client calls. The server\r
75          spawns the FastCGI process once and it continues to run and satisfy client requests until it is explicitly\r
76          terminated. You can also ask the Web server to start multiple copies of a FastCGI application, if you expect\r
77          that concurrent processing will improve the application&#39;s performance.\r
78       </P>\r
79       <P>\r
80          <A NAME="5761"></A> Long-lived applications have two important advantages over short-lived applications:\r
81       </P>\r
82       <BR>\r
83       <BR>\r
84       <UL>\r
85          <LI CLASS="c2">\r
86             <A NAME="7138"></A>\r
87          </LI>\r
88          <LI>\r
89             A short-lived application pays start up overhead on every request; a long-lived application spreads the\r
90             overhead over many requests. For an application that has a heavy start up cost, such as opening a database,\r
91             doing initialization on every call can be very inefficient. Reinitializing for every client is also very\r
92             inefficient for Perl programs, where the interpreter reads through the entire program before executing any\r
93             of it. <A NAME="9204"></A>\r
94          </LI>\r
95          <LI>\r
96             A long-lived application can cache information in memory between requests, allowing it to respond more\r
97             quickly to later requests.\r
98          </LI>\r
99       </UL>\r
100       <A NAME="8733"></A>\r
101       <P>\r
102          FastCGI is not the only way to get a long-lived application on the Web, however. For example, there are many\r
103          existing search engines that are implemented as long-lived applications.\r
104       </P>\r
105       <P>\r
106          <A NAME="8734"></A> In most cases, these applications rely on customized Web servers. In other words, since\r
107          most Web servers do not support long-lived applications, a programmer must code this support into a Web\r
108          server. This approach requires a tremendous amount of work and also ties the application to a particular\r
109          server.\r
110       </P>\r
111       <P>\r
112          <A NAME="8735"></A> Another way to get a long-lived application is to write code that calls routines from the\r
113          Web server&#39;s API. This alternative involves a lot of extra coding, ties the application to a particular\r
114          Web server, and introduces problems of maintainability, scalability, and security.\r
115       </P>\r
116       <P>\r
117          <A NAME="8736"></A> We believe that FastCGI is the most general and flexible strategy for building long-lived\r
118          Web applications.\r
119       </P>\r
120       <BR>\r
121       <BR>\r
122       <H2>\r
123          Separating Application and Server\r
124       </H2>\r
125       <A NAME="8446"></A>\r
126       <P>\r
127          CGI applications must run on the same node as the Web server; FastCGI applications can run on any node that\r
128          can be reached from your Web server using TCP/IP protocols. For example, you might want to run the FastCGI\r
129          application on a high-speed computer server or database engine, and run the Web server on a different node.\r
130       </P>\r
131       <BR>\r
132       <BR>\r
133       <H2>\r
134          FastCGI &quot;Roles&quot;\r
135       </H2>\r
136       <A NAME="8777"></A>\r
137       <P>\r
138          CGI and FastCGI applications are effective ways to allow an application to act as an extension to the Web\r
139          server. CGI provides no explicit support for different kinds of applications: under CGI, every application\r
140          receives an HTTP request, does something with it, and generates an HTTP response. FastCGI provides explicit\r
141          support for several common &quot;roles&quot; that applications can play.\r
142       </P>\r
143       <P>\r
144          <A NAME="8769"></A> The three roles supported by the WebServer 2.0 are:\r
145       </P>\r
146       <BR>\r
147       <BR>\r
148       <UL>\r
149          <LI CLASS="c2">\r
150             <A NAME="8409"></A>\r
151          </LI>\r
152          <LI>\r
153             Responder <A NAME="8410"></A>\r
154          </LI>\r
155          <LI>\r
156             Filter <A NAME="8411"></A>\r
157          </LI>\r
158          <LI>\r
159             Authorizer\r
160          </LI>\r
161       </UL>\r
162       <H3>\r
163          Responder Applications\r
164       </H3>\r
165       <A NAME="8679"></A>\r
166       <P>\r
167          A <EM>responder</EM> application is the most basic kind of FastCGI application: it receives the information\r
168          associated with an HTTP request and generates an HTTP response. Responder is the role most similar to\r
169          traditional CGI programming, and most FastCGI applications are responders.\r
170       </P>\r
171       <BR>\r
172       <BR>\r
173       <H3>\r
174          Filter Applications\r
175       </H3>\r
176       <A NAME="8681"></A>\r
177       <P>\r
178          A <EM>filter</EM> FastCGI application receives the information associated with an HTTP request, plus an extra\r
179          stream of data from a file stored on the Web server, and generates a &quot;filtered&quot; version of the data\r
180          stream as an HTTP response.\r
181       </P>\r
182       <P>\r
183          <A NAME="8421"></A> With filter applications, the system administrator maps a particular MIME-type to a\r
184          particular filter FastCGI application. When a client requests a URL with that MIME-type, the Web server\r
185          invokes the filter application, which processes the file at the specified URL and sends a response (usually\r
186          HTML text) back to the client.\r
187       </P>\r
188       <P>\r
189          <A NAME="8422"></A> For example, suppose you write a filter FastCGI application that converts SGML text to\r
190          HTML, and map the extension .sgml (MIME-type SGML) to your filter FastCGI application. Now, suppose that a\r
191          user requests the following URL:\r
192       </P>\r
193       <BR>\r
194       <BR>\r
195 <PRE>\r
196 <A NAME="8423">/www.aerjug.com/docs/chap1.sgml\r
197 </A>\r
198 </PRE>\r
199       <A NAME="8424"></A>\r
200       <P>\r
201          Given this URL, the Web server passes <CODE>chap1.sgml</CODE> as input to your filter FastCGI application,\r
202          which processes <CODE>chap1.sgml</CODE> and returns an HTML version of it to the requesting client.\r
203       </P>\r
204       <BR>\r
205       <BR>\r
206       <H3>\r
207          Authorizer Applications\r
208       </H3>\r
209       <A NAME="8426"></A>\r
210       <P>\r
211          An <EM>authorizer</EM> FastCGI application receives the information in an HTTP request header and generates a\r
212          decision whether to authorize the request.\r
213       </P>\r
214       <P>\r
215          <A NAME="8428"></A> To mark a FastCGI application as having the authorizer role, the system administrator\r
216          names the application inside the server configuration file, using a directive called\r
217          <CODE>AuthorizeRegion</CODE>. (See the Open Market Web Server manual for information on server configuration\r
218          directives.)\r
219       </P>\r
220       <P>\r
221          <A NAME="8429"></A> When a client requests a URL that meets the <CODE>AuthorizeRegion</CODE> criteria, the Web\r
222          server calls your authorizer FastCGI application. If your application grants authorization (by returning a\r
223          response code of 200), the Web server resumes execution of commands in the <CODE>AuthorizeRegion</CODE>\r
224          section. If your application denies authorization (by returning any other response code), the Web server stops\r
225          processing subsequent commands in the <CODE>AuthorizeRegion</CODE> section, and returns the response from your\r
226          FastCGI application to the client.\r
227       </P>\r
228       <P>\r
229          <A NAME="8431"></A> Authorizer applications can return headers containing environment variables. Other CGI or\r
230          FastCGI programs accessing this request (including other authorizers) can access these environment variables.\r
231          The headers must have the following format:\r
232       </P>\r
233       <BR>\r
234       <BR>\r
235 <PRE>\r
236 <A NAME="8432">Variable-<EM>name</EM>: <EM>value</EM>\r
237 </A>\r
238 </PRE>\r
239       <A NAME="8433"></A>\r
240       <P>\r
241          For example, the following header\r
242       </P>\r
243       <BR>\r
244       <BR>\r
245 <PRE>\r
246 <A NAME="8434">Variable-AUTH_METHOD: database lookup\r
247 </A>\r
248 </PRE>\r
249       <A NAME="8435"></A>\r
250       <P>\r
251          causes the environment variable <CODE>AUTH_METHOD</CODE> to be set to <CODE>&quot;database lookup&quot;</CODE>\r
252          for this request. Other CGI or FastCGI applications running on this request can access the value of\r
253          <CODE>AUTH_METHOD</CODE>.\r
254       </P>\r
255       <P>\r
256          <A NAME="8437"></A> Authorizer applications cannot successfully read from standard input. Any attempts to read\r
257          from standard input result in an immediate EOF.\r
258       </P>\r
259       <P>\r
260          <A NAME="8438"></A> All data that authorizer applications write to standard error will get written to the\r
261          traditional server error logs.\r
262       </P>\r
263       <BR>\r
264       <BR>\r
265       <H1>\r
266          Writing FastCGI Applications\r
267       </H1>\r
268       <A NAME="9301"></A>\r
269       <P>\r
270          The work involved in writing a FastCGI application depends in large part on the I/O libraries that you use.\r
271          This manual describes how to write FastCGI applications in terms of the Open Market libraries, which are\r
272          available for C, Perl, and Tcl. FastCGI is an open standard and you are welcome to build your own libraries\r
273          for other languages as well, but this manual focuses on building FastCGI applications in the context of the\r
274          Open Market libraries.\r
275       </P>\r
276       <P>\r
277          <A NAME="9443"></A>\r
278       </P>\r
279       <P>\r
280          <A NAME="9450"></A> In general, the goal of the libraries is to make the job of writing a FastCGI application\r
281          as much like writing a CGI application as possible. For example, you use the same techniques for query string\r
282          decoding, HTML output to stdout, use of environment variables, and so on. When you use our libraries, porting\r
283          CGI applications to FastCGI is mostly a matter of restructuring the code to take advantage of FastCGI features\r
284          and libraries.\r
285       </P>\r
286       <BR>\r
287       <BR>\r
288       <H2>\r
289          Code Structure\r
290       </H2>\r
291       <A NAME="9470"></A>\r
292       <P>\r
293          The main task of converting a CGI program into a FastCGI program is separating the initialization code from\r
294          the code that needs to run for each request. The structure should look something like this:\r
295       </P>\r
296       <BR>\r
297       <BR>\r
298 <PRE>\r
299 <A NAME="9471">Initialization code\r
300 </A>\r
301 <A NAME="9472">Start of response loop\r
302 </A>\r
303  <A NAME="9473">  body of response loop\r
304 </A>\r
305 <A NAME="9474">End of response loop\r
306 </A>\r
307 </PRE>\r
308       <A NAME="9475"></A>\r
309       <P>\r
310          The <EM>initialization code</EM> is run exactly once, when the application is initialized. Initialization code\r
311          usually performs time-consuming operations such as opening databases or calculating values for tables or\r
312          bitmaps.\r
313       </P>\r
314       <P>\r
315          <A NAME="9477"></A> The <EM>response loop</EM> runs continuously, waiting for client requests to arrive. The\r
316          loop starts with a call to <CODE>FCGI_Accept</CODE>, a routine in the FastCGI library. The\r
317          <CODE>FCGI_Accept</CODE> routine blocks program execution until a client requests the FastCGI application.\r
318          When a client request comes in, <CODE>FCGI_Accept</CODE> unblocks, runs one iteration of the response loop\r
319          body, and then blocks again waiting for another client request. The loop terminates only when the system\r
320          administrator or the Web server kills the FastCGI application.\r
321       </P>\r
322       <BR>\r
323       <BR>\r
324       <H2>\r
325          Initial Environment Variables\r
326       </H2>\r
327       <A NAME="9786"></A>\r
328       <P>\r
329          When a FastCGI process starts up, it has not yet accepted a request, and therefore none of the CGI environment\r
330          variables are set.\r
331       </P>\r
332       <P>\r
333          <A NAME="9787"></A> You set the initial environment of a FastCGI process started by the <CODE>AppClass</CODE>\r
334          directive using the <CODE>-initial-env</CODE> option. The process would use this environment to configure its\r
335          options and locate files or databases.\r
336       </P>\r
337       <P>\r
338          <A NAME="9829"></A> In FastCGI processes started by the <CODE>AppClass</CODE> directive with the -affinity\r
339          option, the <CODE>FCGI_PROCESS_ID</CODE> variable is set in the initial environment (not in the environment of\r
340          a request). <CODE>FCGI_PROCESS_ID</CODE> is a decimal number in the range 0 to N - 1 where N is the number of\r
341          processes (argument to the <CODE>-processes</CODE> option to <CODE>AppClass</CODE>). The process would use\r
342          <CODE>FCGI_PROCESS_ID</CODE> in conjunction with other variables to locate session-related files or databases\r
343          during restart.\r
344       </P>\r
345       <BR>\r
346       <BR>\r
347       <H2>\r
348          Per-Request Environment Variables\r
349       </H2>\r
350       <A NAME="9481"></A>\r
351       <P>\r
352          In general, FastCGI uses the same per-request environment variables as CGI, and you access the values of\r
353          environment variables in FastCGI applications just as you would in CGI applications. The only differences are\r
354          as follows:\r
355       </P>\r
356       <BR>\r
357       <BR>\r
358       <UL>\r
359          <LI CLASS="c2">\r
360             <A NAME="9483"></A>\r
361          </LI>\r
362          <LI>\r
363             In Authorizer FastCGI applications, the Web server unsets the <CODE>PATH_INFO</CODE>,\r
364             <CODE>PATH_TRANSLATED</CODE>, and <CODE>CONTENT_LENGTH</CODE> variables. <A NAME="9484"></A>\r
365          </LI>\r
366          <LI>\r
367             In Filter FastCGI applications, the Web server sets two additional environment variables: \r
368             <UL>\r
369                <LI CLASS="c2">\r
370                   <A NAME="9486"></A>\r
371                </LI>\r
372                <LI>\r
373                   <CODE>FILE_LAST_MOD</CODE>: The Web server sets <CODE>FILE_LAST_MOD</CODE> to the date and time that\r
374                   filter input file was last modified. The format is the number of seconds since midnight (UTC),\r
375                   January 1, 1970. <A NAME="9488"></A>\r
376                </LI>\r
377                <LI>\r
378                   <CODE>FCGI_DATA_LENGTH</CODE>: The application reads at most <CODE>FCGI_DATA_LENGTH</CODE> bytes from\r
379                   the data stream before receiving the end-of-stream indication.\r
380                </LI>\r
381             </UL>\r
382             <A NAME="9490"></A>\r
383          </LI>\r
384          <LI>\r
385             FastCGI sets <CODE>FCGI_ROLE</CODE> for each request to <CODE>RESPONDER</CODE>, <CODE>AUTHORIZER</CODE>, or\r
386             <CODE>FILTER</CODE>.\r
387          </LI>\r
388       </UL>\r
389       <H2>\r
390          Building FastCGI Applications in C\r
391       </H2>\r
392       <A NAME="9049"></A>\r
393       <P>\r
394          The Software Development Toolkit that accompanies WebServer 2.0 contains two libraries, fcgi_stdio and\r
395          fcgiapp, for building FastCGI applications in C.\r
396       </P>\r
397       <P>\r
398          <A NAME="9723"></A> The fcgi_stdio library implements our philosophy of making FastCGI applications similar to\r
399          CGI applications, and provides full binary compatibility between FastCGI applications and CGI applications:\r
400          you can run the same C binary as either CGI or FastCGI.\r
401       </P>\r
402       <P>\r
403          <A NAME="9545"></A> The fcgiapp library is more specific to FastCGI, and doesn&#39;t attempt the veneer of\r
404          CGI.\r
405       </P>\r
406       <P>\r
407          <A NAME="9731"></A> We recommend that you use the fcgi_stdio library, and this manual describes the routines\r
408          in that library. The documentation for the fcgiapp library is in the code in the development kit.\r
409       </P>\r
410       <BR>\r
411       <BR>\r
412       <H2>\r
413          Building FastCGI Applications in Perl\r
414       </H2>\r
415       <A NAME="9581"></A>\r
416       <P>\r
417          To build FastCGI applications in Perl, you need a FastCGI-savvy version of Perl, plus the FastCGI extension to\r
418          Perl. We build FastCGI-savvy versions of the Perl interpreter for several common platforms and make them\r
419          available on our Website. For details and examples, see Chapter <A HREF="ch3perl.htm#3659">3, &quot;Developing\r
420          FastCGI Applications in Perl,&quot; on page 17</A>.\r
421       </P>\r
422       <BR>\r
423       <BR>\r
424       <H2>\r
425          Building FastCGI Applications in Tcl\r
426       </H2>\r
427       <A NAME="9586"></A>\r
428       <P>\r
429          To build FastCGI applications in Tcl, you need a FastCGI-savvy version of Tcl. We build FastCGI-savvy versions\r
430          of the Tcl interpreter for several common platforms and make them available on our Website. For details and\r
431          examples, see Chapter <A HREF="ch4tcl.htm#3659">4, &quot;Developing FastCGI Applications in Tcl,&quot; on page\r
432          19</A>.\r
433       </P>\r
434       <BR>\r
435       <BR>\r
436       <H1>\r
437          Implementation Details\r
438       </H1>\r
439       <A NAME="8066"></A>\r
440       <P>\r
441          The FastCGI application libraries are designed to shield you from the details of the FastCGI design. This\r
442          section is designed for the curious reader who would like some low-level understanding. If you are not curious\r
443          about the implementation, you can happily skip this section.\r
444       </P>\r
445       <P>\r
446          <A NAME="8554"></A> As shown in the following figure, CGI applications use the three standard POSIX streams\r
447          (<CODE>stdin</CODE>, <CODE>stdout</CODE>, and <CODE>stderr</CODE>), plus environment variables, to communicate\r
448          with an HTTP server.\r
449       </P>\r
450       <P>\r
451          <A NAME="8359"></A> <IMG ALT="error-file:TidyOut.log" SRC="ch1intra.gif">\r
452       </P>\r
453       <P>\r
454          <A NAME="4295"></A>\r
455       </P>\r
456       <BR>\r
457       <BR>\r
458       <H5>\r
459          Figure 1:  Flow of Data in CGI\r
460       </H5>\r
461       <A NAME="9001"></A>\r
462       <P>\r
463          The fundamental difference between FastCGI and CGI is that FastCGI applications are long-lived, which means\r
464          that the Web Server needs to rendezvous with a running application, rather than starting the application in\r
465          order to explicitly communicate with it.\r
466       </P>\r
467       <P>\r
468          <A NAME="9110"></A> The FastCGI implementation basically creates a bidirectional connection between two\r
469          processes that have no relationship. FastCGI uses a single connection for all the data associated with an\r
470          application -- stdin, stdout, stderr, and environment variables. The data on the connection is encapsulated\r
471          using a FastCGI protocol that allows stdin and the environment variables to share the same half connection (on\r
472          the way in) and stdout and stderr to share the half connection (on the way out).\r
473       </P>\r
474       <P>\r
475          <A NAME="9020"></A> On the input side, the FastCGI application receives data on the connection, unpacks it to\r
476          separate stdin from the environment variables and then invokes the application. On the output side, FastCGI\r
477          wraps stdout and stderr with appropriate protocol headers, and sends the encapsulated data out to the server.\r
478       </P>\r
479       <P>\r
480          <A NAME="9032"></A> Since a FastCGI application does not always run on the same node as the HTTP server, we\r
481          support two implementations of the connection: a <EM>stream pipe</EM><A HREF="#9645"><SUP>1</SUP></A>, for\r
482          communications on the same machine, and TCP streams, for communication when the client and the server are on\r
483          different machines.\r
484       </P>\r
485       <P>\r
486          <A NAME="8576"></A> <IMG ALT="error-file:TidyOut.log" SRC="ch1inta1.gif">\r
487       </P>\r
488       <BR>\r
489       <BR>\r
490       <H5>\r
491          Figure 2:  Flow of Data in FastCGI when server and application are on different machines\r
492       </H5>\r
493       <H2>\r
494          The fcgi_stdio Library: I/O Compatibility\r
495       </H2>\r
496       <A NAME="8977"></A>\r
497       <P>\r
498          The implementation for I/O compatibility is that the library <CODE>fcgi_stdio.h</CODE> contains macros to\r
499          translate the types and procedures defined in stdio.h into the appropriate FastCGI calls. For example,\r
500          consider a FastCGI program written in C containing the following line of code:\r
501       </P>\r
502       <BR>\r
503       <BR>\r
504 <PRE>\r
505 <A NAME="5877">fprintf(stdout, &quot;&lt;H2&gt;Aerobic Juggling&lt;/H2&gt;/n&quot;);\r
506 </A>\r
507 </PRE>\r
508       <A NAME="9659"></A> <CODE>fcgi_stdio.h</CODE>\r
509       <P>\r
510          header file contains the macro\r
511       </P>\r
512       <BR>\r
513       <BR>\r
514 <PRE>\r
515 <A NAME="6403">#define fprintf FCGI_fprintf\r
516 </A>\r
517 </PRE>\r
518       <A NAME="6402"></A>\r
519       <P>\r
520          So the preprocessor translates the <CODE>fprintf</CODE> call into the following call:\r
521       </P>\r
522       <BR>\r
523       <BR>\r
524 <PRE>\r
525 <A NAME="6411">FCGI_fprintf(stdout, &quot;&lt;H2&gt;Aerobic Juggling&lt;/H2&gt;/n&quot;);\r
526 </A>\r
527 </PRE>\r
528       <A NAME="5888"></A> <CODE>FCGI_fprintf</CODE>\r
529       <P>\r
530          takes the same arguments as <CODE>fprintf</CODE>.\r
531       </P>\r
532       <P>\r
533          <A NAME="9664"></A> The implementation of FCGI_fprintf tests the file to see if it is a normal C stream or a\r
534          FastCGI stream, and calls the appropriate implementation.\r
535       </P>\r
536       <P>\r
537          <A NAME="6463"></A> The <CODE>fcgi_stdio.h</CODE> header file contains macros to translate calls to all ISO\r
538          stdio.h routines (and all conventional Posix additions, such as <CODE>fileno</CODE>, <CODE>fdopen</CODE>,\r
539          <CODE>popen</CODE>, and <CODE>pclose</CODE>) into their FastCGI equivalents.\r
540       </P>\r
541       <BR>\r
542       <BR>\r
543       <H2>\r
544          The fcgi_stdio Library: Binary compatibility\r
545       </H2>\r
546       <A NAME="9579"></A>\r
547       <P>\r
548          The fcgi_stdio library provides full binary compatibility between FastCGI applications and CGI applications:\r
549          you can run the same C binary as either CGI or FastCGI.\r
550       </P>\r
551       <P>\r
552          <A NAME="9580"></A> The implementation is in FCGI_Accept: the FCGI_Accept function tests its environment to\r
553          determine whether the application was invoked as a CGI program or an FastCGI program. If it was invoked as a\r
554          CGI program, the request loop will satisfy a single client request and then exit, producing CGI behavior.\r
555       </P>\r
556       <P>\r
557          <A NAME="8957"></A>\r
558       </P>\r
559       <P>\r
560       </P>\r
561       <HR>\r
562       <BR>\r
563        <A HREF="cover.htm">[Top]</A> <A HREF="ap_guide.htm">[Prev]</A> <A HREF="ch2c.htm">[Next]</A> <A HREF=\r
564       "ap_guida.htm">[Bottom]</A> \r
565       <HR>\r
566       <BR>\r
567        <SUP>1</SUP><A NAME="9645"></A>\r
568       <P>\r
569          UNIX Network Programming, W. Richard Stevens, 1990 Prentice-Hall, Section 7.9\r
570       </P>\r
571       <P>\r
572          <!-- This file was created with Quadralay WebWorks Publisher 3.0.3 -->\r
573          <!-- -->\r
574          <!-- For more information on how this document, and how the rest of -->\r
575          <!-- this server was created, email yourEmail@xyzcorp.com -->\r
576          <!-- -->\r
577          <!-- Last updated: 04/15/96 08:00:13 -->\r
578       </P>\r
579    </BODY>\r
580 </HTML>\r
581 \r