# fastcgipp_v2.1 **Repository Path**: love2share/fastcgipp_v2.1 ## Basic Information - **Project Name**: fastcgipp_v2.1 - **Description**: A C++ FastCGI and Web development platform:http://isatec.ca/fastcgipp/ - **Primary Language**: C++ - **License**: BSL-1.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-12-19 - **Last Updated**: 2024-06-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README fastcgi++ 2.1 Aug 23, 2012 Eddie Carle Introduction 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. Session 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. Features * Support for multiple locales and characters sets including wide Unicode and utf-8 * Internally manages simultaneous requests instead of leaving that to the user * Establishes session data into usable data structures * Implements a task manager that can not only easily communicate outside the library, but with separate threads * Provides a familiar io interface by implementing it through STL iostreams * Complete compliance with FastCGI protocol version 1 Overview 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 session 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 session 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. Dependencies * Boost C++ Libraries >1.35.0 * Posix compliant OS (socket stuff) =============================================================================== yum install boost-devel ./configure --disable-shared --enable-static make && make install 再不指定prefix的路径的情况下,GCC编译也就会到默认的路径去寻找头文件与库文件。这里, 我选择编译成了静态库的形式,不需要数据库有关的操作,不需要编译进去. g++ -o main -lboost_system-mt -lboost_thread-mt -lfastcgipp -L/usr/lib64/mysql -lmysqlclient main.cpp 验证: 由于是一个FastCgi程序,所以就需要一个lighthttpd项目中一个fastcgi启动器spawn-fastcgi 更改Nginx配置文件 nginx.conf 在server中加入fastcgi配置: location ~\.fcgi$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.fcgi; fastcgi_param SCRIPT_FILENAME /$fastcgi_script_name; include fastcgi_params; } 重启Nginx重新加载配置文件。   运行spawn-fastcgi程序:       spawn-fastcgi -a 127.0.0.1 -C 20 -p 9000 main   成功提示:spawn-fcgi: child spawned successfully: PID: 13404   现在打开浏览器,输入localhost/test.fcgi就能看到C++代码输出的值了。 spawn_fastcgi的安装、部署与配置 下载地址: https://github.com/lighttpd/spawn-fcgi 或者 http://redmine.lighttpd.Net/projects/spawn-fcgi/news 这里使用的是1.6.4的版本 https://github.com/lighttpd/spawn-fcgi/releases/tag/v1.6.4 (1)解压,进入源码目录,方法同上,新建/home/wensheng/fastcgi/spawn/目录。 在配置之前先运行./autogen.sh (2)配置 ./configure --prefix=/home/wensheng/fastcgi/spawn/ (3)然后依次输入 make make install (4)进入到_install目录 把bin目录下生成的程序拷贝到nginx服务器的安装目录下的sbin目录里面去,例如我的安装目录是/user/sbin