FastCGI / SCGI pre-fork

随声附和 提交于 2019-12-24 02:18:21

问题


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?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/6797222/fastcgi-scgi-pre-fork

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!