Question

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)
Était-ce utile?

La 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.

Autres conseils

I do not know whether your problem has the same origin as mine had, but at least it has the same symptoms.

There are different versions of the tiny-fcgi example. I first tried the one given here (example 1). This failed with an internal server error. However, the example given here (which does basically the same) works. The small but crucial difference is that the working code uses

getenv("SERVER_NAME")

instead of

getenv("SERVER_HOSTNAME")

not exactly the same for me, but if i avoid using getenv the example runs without errors, have to discover why getenv leads into error

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top