FCGI FCGX_Accept_r 函数 阻塞 block 问题
用curl chrome 都无法正确连接 fcgi
调试C代码发现阻塞在FCGX_Accept_r 上,我翻烂了搜索引擎都找不到答案,但是最终解决了,特地把这个坑记一下
最终发现curl等用的是http协议,而fcgi是另一种协议,所以curl发过去的,fcgi不会回应
需要nginx做转发才行
ningx.conf:
location /fcgi_svr{
fastcgi_pass 192.168.99.193:6565;
}
另附fcgi例程
static void *doit(void *a)
{
int rc;
FCGX_Request request;
int sockfd=(int)a;
int err = FCGX_InitRequest(&request, sockfd, FCGI_FAIL_ACCEPT_ON_INTR);
LOG("sock: %d, err %d \n",sockfd, err);
for (;;)
{
LOG("in HERE \n");
rc = FCGX_Accept_r(&request);
LOG("in HERE \n");
if (rc < 0)
{
LOG("err:%d\n",rc);
break;
}
char* file_name=FCGX_GetParam("FILE_NAME" ,request.envp);
LOG("upload file:%s\n",file_name);
FCGX_FPrintF(request.out,
"Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello! ");
sleep(2);
FCGX_Finish_r(&request);
}
return NULL;
}
#define THREAD_COUNT 5
int main(void)
{
int i;
pthread_t id[THREAD_COUNT];
FCGX_Init();
char *p = getenv("FCGI_WEB_SERVER_ADDRS");
printf("addrlist %s\n",p);
char socket[24] =
{ ':' };
strcat(socket, "6565");
int sockfd = FCGX_OpenSocket(socket, 1024);
LOG("listen addr=[%s] sockfd=[%d]\n", socket, sockfd);
for (i = 1; i < THREAD_COUNT; i++)
pthread_create(&id[i], NULL, doit, (void*)sockfd);
doit((void*)sockfd);
return 0;
}