【发布时间】:2015-11-24 01:51:02
【问题描述】:
我正在尝试创建用 C 编写的简单 FastCGI 应用:
#include <fcgiapp.h>
#include <stdio.h>
int main()
{
int sockfd = FCGX_OpenSocket("127.0.0.1:9000", 1024);
FCGX_Request request;
FCGX_Init();
FCGX_InitRequest(&request, sockfd, 0);
while (FCGX_Accept_r(&request) == 0)
{
printf("Accepted\n");
FCGX_FPrintF(request.out, "Content-type: text/html\r\n\r\n<h1>Hello World!</h1>");
FCGX_Finish_r(&request);
}
}
它工作正常 - 当我从浏览器调用它时,它会显示带有“Hello World!”的页面消息。
问题是“while”中的代码工作两次,即我在终端中看到以下输出:
[root@localhost example]$ ./hello
Accepted
Accepted
为什么每次请求都会打印两次“Accepted”? 如果我在这里放真正的代码,例如查询一个数据库,它也会被执行两次。
【问题讨论】: