如果应用程序作为一个 CGI 程序被调用,那么第一次调用 Accept 时,返回 0,第二
次总是返回-1,产生 CGI 行为。(请详见 20 页的"FCGI_Accept (3)" )
注意,在 CGI 中鼓励用小脚本,然而在 FastCGI 中则鼓励使用组合式的脚本。你可以
在从新构想你的程序的全局结构,来获得 FastCGI 的高性能。
例 1: TinyFastCGI
这是一个用 C 语言写的一个简单 FastCGI 应答程序例子:
#include "fcgi_stdio.h"
#include <stdlib.h>
int count;
void initialize(void)
{
count=0;
}
void main(void)
{
initialize();
while (FCGI_Accept() >= 0) {
printf("Content-type: text/html "
" "
"<title>FastCGI Hello! (C, fcgi_stdio library)</title>"
"<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>"
"Request number %d running on host <i>%s</i> ",