小编Ole*_*her的帖子

FCGX_Accept_r 在 C 上的简单 FastCGI 应用程序中运行两次

我正在尝试创建用 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);
    }
}
Run Code Online (Sandbox Code Playgroud)

它工作正常 - 当我从浏览器调用它时,它会显示带有“Hello World!”的页面。信息。

问题是“while”中的代码工作两次,即我在终端中看到以下输出:

[root@localhost example]$ ./hello 
Accepted 
Accepted
Run Code Online (Sandbox Code Playgroud)

为什么每个请求都会打印“Accepted”两次?如果我把真正的代码放在这里,例如查询一个数据库,它也会被执行两次。

c fastcgi nginx

3
推荐指数
1
解决办法
693
查看次数

标签 统计

c ×1

fastcgi ×1

nginx ×1