Fog Creek Software
Discussion Board




FastCGI or Apache Module

I have to develop a portable (Windows, Linux) application in C++ which will have browser/http interface. The application will cache large amounts of data in memory, so CGI does not seem to be a good choice. I see two ways to approach the problem - Apache Module or FastCGI. Here are a few thoughts about it:

- FastCGI is supported on multiple web servers (including IIS), which is nice. However, installing Apache on the machine where the application will run is an acceptable requirement.
- The API for creating an Apache module might change. For instance modules created for version 1.3 would not work with 2.0. On the other hand, after the major redesign in 2.0 it's less likely to happen in the future.
- I do not expect lots of requests (small amount of requests - lots of processing, the application will be used by one user most of the time), so the better performance of an Apache module (running in the same process) does not matter.
- Most of the things related to FastCGI seem to be in an unfinished, or even worse – abandoned state. Binaries dated 2001 with version 0.6, websites that haven’t been updated for a while … I am not sure whether FastCGI will be developed or even supported well in future.

Have you used FastCGI or created Apache modules before? What are your impressions about the ease of development, debugging, reliability? What about the future of FastCGI? Can you recommend me some examples to start with?

Alexander Chalucov (www.alexlechuck.com)
Sunday, June 29, 2003

I've no experience with what you're wondering about.

However, it seems to me you're going a step lower than really necessary. Is there a reason you're going so low-level? Or would it be, perhaps, more reasonable to use a web-programming platform like PHP?

If PHP is out because of the cache requirement, what about JSP, ASP, directly modifying an embeddable web server, etc.?

I only mean to illustrate that I think there are significantly more than your "two ways to approach the problem". I don't know what would work best, as I've done little web programming, but it doesn't sound like you've investigated many possibilities.

Mike Swieton
Sunday, June 29, 2003

I have to agree with Mike.

It doesn't seem that any application with an browser/HTTP interface needs to be completely written in C++. 

If your application absolutely needs to the power/performance of C++ then I recommend using a client/server design.  Build a simple client front end in Java or PHP (I recommend PHP) that connects to your backend C++ server to do the processing.  This has the added benefit of splitting up the browser/UI code from the server code. 

Wayne Venables
Sunday, June 29, 2003

If you have to do it in C++ and need HTTP support look for a C++ API that allows you to run a simple standalone embedded http server within your app.

Tom Vu
Sunday, June 29, 2003


I've written a number of C++ apps with browser
interfaces, however I never store large amounts
of data in memory. Best to keep the data in a db.
However if you really want to continue down this
route, you could use a cross platform shared memory
library to load the data into memory once, and
access it from each cgi call.

However I prefer the above mentioned idea of
embedding a small http server into the application,
since this can be done relatively quickly...

Frank
Monday, June 30, 2003

I've used FastCGI; I prefer the process model to that of using an Apache module, because you can tune each FastCGI app individually as to number of server processes, start speed, etc.

Haven't used it on Windows, though.

Phillip J. Eby
Monday, June 30, 2003

Thank you all for your answers.
The choice of C++ is done mainly for performance reasons. I could use some PHP/ASP/JSP but it would just add a layer of complexity with no benefit.
The suggestions to embed a simple web server are quite reasonable though. I might consider this approach too. Can anybody suggest a good BSD license C/C++ embeddable web server that would work on both POSIX and Win32? Using cygwin on Win32 is perfectly acceptable.

Alexander Chalucov (www.alexlechuck.com)
Monday, June 30, 2003

Using FastCGI down here, and it works very well. High load, lots of small request (about 15 million/day).

Oh, FastCGI is far from being abandoned (http://www.fastcgi.com)

Leonardo Herrera
Monday, June 30, 2003

*  Recent Topics

*  Fog Creek Home