The fastcgi++ library started out as a C++ alternative to the official FastCGI developers kit. Although the official developers kit provided some degree of C++ interface, it was very limited. The goal of this project was to provide a framework that offered all the facilities that the C++ language has to offer. Over time the scope broadened to the point that it became more than just a simple protocol library, but a platform to develop web application under C++. To the dismay of many, this library has zero support for the old CGI protocol. The consensus was that if one were to be developing web applications under C++, efficient memory management and CPU usage would be a top priority, not CGI compatibility. Effective management of simultaneous requests without the need for multiple threads is something that fastcgi++ does best. Environment data is organized into meaningful data types as opposed to a series of text strings. Internationalization and Unicode support is another top priority. The library is templated to allow internal wide character use for efficient text processing while code converting down to utf-8 upon transmission to the client.
The fastcgi++ library is built around three classes. Fastcgipp::Manager handles all task and request management along with the communication inside and outside the library. Fastcgipp::Transceiver handles all low level socket io and maintains send/receive buffers. Fastcgipp::Request is designed to handle the individual requests themselves. The aspects of the FastCGI protocol itself are defined in the Fastcgipp::Protocol namespace.
The Fastcgipp::Request class is a pure virtual class. The class, as is, establishes and parses environment().data. Once complete it looks to user defined virtual functions for actually generating the response. A response shall be outputted by the user defined virtuals through an output stream. Once a request has control over operation it maintains it until relinquishing it. Should the user know a request will sit around waiting for data, it can return control to Fastcgipp::Manager and have a message sent back through the manager when the data is ready. The aspects of the environment().are build around the Fastcgipp::Http namespace.
Fastcgipp::Manager basically runs an endless loop (which can be terminated through POSIX signals or a function call from another thread) that passes control to requests that have a message queued or the transceiver. It is smart enough to go into a sleep mode when there are no tasks to complete or data to receive.
Fastcgipp::Transceiver's transmit half implements a cyclic buffer that can grow indefinitely to insure that operation does not halt. The send half receives full frames and passes them through Fastcgipp::Manager onto the requests. It manages all the open connections and polls them for incoming data.
fastcgi++ installs just the same as any library out there the uses the GNU build system...
tar -xvjf fastcgi++-2.1.tar.bz2
If you want to build the examples do...
A pkg-config file will be installed so you can compile against the libraries with
g++ -o script.fcgi script.cpp
pkg-config –libs –cflags fastcgi++
This is a collection of tutorials that should cover most aspects of the fastcgi++ library
Hello World in Five Languages : A simple tutorial outputting "Hello World" in five languages using UTF-32 internally and UTF-8 externally.
Echo : An example of a FastCGI application that echoes all user data and sets a cookie
Display The Gnu : A tutorial explaining how to display images and non-html data as well as setting locales
Delayed response : A tutorial covering the use of the task manager and threads to have requests efficiently communicate with non-fastcgi++ data.
Sessions : An example of how to utilize the internal mechanism in fastcgi++ to handle HTTP sessions.
Database : An example of the explains the usage of fastcgi++'s SQL facilities with a MySQL database.