分类: C/C++
2009-12-02 14:49:28
// gcc -I/usr/include/fastcgi -lfcgi testfastcgi.c -o test.fastcgi #include#include #include #include #include #define LISTENSOCK_FILENO 0 #define LISTENSOCK_FLAGS 0 int main(int argc, char** argv) { openlog ("testfastcgi", LOG_CONS|LOG_NDELAY, LOG_USER); int err = FCGX_Init (); /* call before Accept in multithreaded apps */ if (err) { syslog (LOG_INFO, "FCGX_Init failed: %d", err); return 1; } FCGX_Request cgi; err = FCGX_InitRequest(&cgi, LISTENSOCK_FILENO, LISTENSOCK_FLAGS); if (err) { syslog (LOG_INFO, "FCGX_InitRequest failed: %d", err); return 2; } while (1) { err = FCGX_Accept_r(&cgi); if (err) { syslog (LOG_INFO, "FCGX_Accept_r stopped: %d", err); break; } char** envp; int size = 200; for (envp = cgi.envp; *envp; ++envp) size += strlen(*envp) + 11; char* result = (char*) alloca(size); strcpy (result, "Status: 200 OK\r\nContent-Type: text/html\r\n\r\n"); strcat (result, " testcgi \r\n"); for (envp = cgi.envp; *envp; ++envp) { strcat(result, "
\r\n"); FCGX_PutStr(result, strlen(result), cgi.out); FCGX_Finish_r(&cgi); } FCGX_ShutdownPending(); return 0; }- "); strcat(result, *envp); strcat(result, "
\r\n"); } strcat(result, "
4.编译并运行
gcc -I/usr/include/fastcgi -lfcgi testfastcgi.c -o test.fastcgi
在IE中输入:
如果成功,即可看到如下信息:
参考文章: