How to extend C++ HTTP server with FastCGI applications?

ぐ巨炮叔叔 提交于 2019-12-08 03:09:30

问题


I am writing a C++ HTTP server. But because developing in C++ is slower as for example in PHP I want to also support FastCGI applications (PHP via FastCGI, Python via FastCGI, etc.). So I want to use something similar to mod_fcgi (for Apache). Does someone know a good C++ FastCGI library (not for applications but for the webserver) ? I use the Poco library to write the webserver.

Another solution could be to use an PHP interpreter directly in my C++ server. Does anybody know some examples for this?

All solutions must have performance in mind.


回答1:


If you are writing a CMS system in C++, you should checkout CppCMS web framework in C++, its seems to be very fast.

If you are wanting to do it more from scratch and write the HTTP server, boost has some examples on how to setup an HTTP server here.

Now if you want to use CGI which is the slowest option, there is a GNU Cdicc library for handling CGI.




回答2:


I've been looking at this topic yesterday. As you may know, fastcgi is built over tcp or unix socket waiting for a connection with a specific protocol.

The scheme of a request is the following: A client connects to the webserver, which connects to the fastcgi application. Depending on the implementation (the specs says that the webserver gives a file descriptor connected to the webclient (the accept() sockfd) to the fastcgi applciation. I have not seen such a behaviour with nginx.

How can you experiment?

  1. Install nginx (The configuration is very simple, see documentation)
  2. Compile php (a simple ./configure --enable-fastcgi && make will do. Takes 30 seconds for me)
  3. launch php-cgi on localhost port 9000 (./sapi/cgi/php-cgi -b 127.0.0.1:9000)
  4. tcpdump / wireshark the output
  5. Now stop php, and run a simple tcp server (for instance nc -l 9000)

I found fcgi specification which is very usefull if you want to write your own library. I've not been (yet) able to find C/C++ code for a client to fcgi, but it can easily be found for perl.




回答3:


I could not find a FastCGI client, so I wrote it myself. It was a lot of work, but i succeeded :) It is a lot faster then plain old CGI (duh!).



来源:https://stackoverflow.com/questions/6928012/how-to-extend-c-http-server-with-fastcgi-applications

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