Search code examples
c++cfastcgilighttpd

What is the difference between fcgi_stdio and fcgiapp?


I am trying to get started with fastcgi development, therefor I download the reference implementation of libfcgi and tried to get a testprogram to run with lighttpd. Since fcgi_stdio allows for cgi backwards compatibility, I decided to start with that. However I could not get the examples/tiny-fcgi.c to work with lighttpd, it yielded an internal server errror 500, the same configuration allows to run the lighttpd example program (http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_ModFastCGI, below C/C++ FastCGI on lightty named socket) flawless. However it is totally unclear to me why the default supplied example would not work.

Questions:

  1. What is wrong with the examples/tiny-fcgi.c example from the reference implementation causing lighttpd to return error 500?
  2. Which implementation of fastcgi is preferable for c++ development (fcgi_stdio, fcgiapp, Other)? (There is something for streams in the fcgi pack, however I failed to find good/any documentation)

Solution

  • I have tested the unmodified example (Ubuntu/13.10/amd-64, Apache/2.4.6, libapache2-mod-fastcgi/2.4.7~0910052141-1.1, libfcgi-dev/2.4.0-8.1ubuntu4) and it runs ok:

    manuelz@garibaldi:~$ curl habrich/tiny-fcgi
    <title>FastCGI Hello! (C, fcgi_stdio library)</title>
    <h1>FastCGI Hello! (C, fcgi_stdio library)</h1>
    Request number 2 running on host <i>habrich</i>
    

    Answers:

    1. Hard to tell without knowing your configuration, but here's a shot in the dark: getenv will return NULL if SERVER_NAME is undefined.
    2. fcgiapp is the base implementation: I would use that one for new development. fcgi_stdio is a wrapper for compatibility with CGI: use that for migrating legacy CGI projects. Quote:

      fcgi_stdio is implemented as a thin layer on top of fcgiapp

    You can find decent documentation for fcgiapp in the fcgiapp.h header.