FastCGI / SCGI pre-fork

I've been trying to implement a web server gateway (for fun and educational purposes) and I have some questions about the core architecture behind FastCGI/SCGI with respect to the pre-fork model.

How do FastCGI/SCGI implementations handle communication in pre-fork scenarios? AFAIK, the gateway only has one socket to connect to the FastCGI server. Normally, there is a parent process that accepts connections from the gateway and hands off the work to one of the pre-forked workers.

Since the connections are established after the children are forked, how are you supposed to have the children use these sockets to communicate with the gateway?


I hope I understood the question.

The server socket should be created by the parent process; when it forks, children inherit that socket making it a shared resource. Then, I suppose, each child tries to accept() connections concurrently.

As a reference I found this document (see "accept serialization") discussing starvation issue when listening on multiple sockets, and this SO discussion on sharing sockets


One options is file descriptor passing over UNIX domain socket. Stevens UNP has basic example.

人吐槽 人点赞



用户名: 密码:
验证码: 匿名发表


查看评论:FastCGI / SCGI pre-fork