使用fastcgi++编写fastcgi应用初探(一)
fastcgi++作为一个完全C++编写的fastcgi应用开发包,封装了很多功能,比如参数提取,session,mysql数据库连接管理等最大限度的简化cgi编程。
编写一个简单的helloworld的fastcgi应用。
-
#include <fstream>
-
#include <boost/date_time/posix_time/posix_time.hpp>
-
-
#include <fastcgi++/request.hpp>
-
#include <fastcgi++/manager.hpp>
-
-
void error_log(const char* msg)
-
{
-
using namespace std;
-
using namespace boost;
-
static ofstream error;
-
if(!error.is_open())
-
{
-
error.open("/tmp/errlog", ios_base::out | ios_base::app);
-
error.imbue(locale(error.getloc(), new posix_time::time_facet()));
-
}
-
-
error << '[' << posix_time::second_clock::local_time() << "] " << msg << endl;
-
}
-
-
class Helloworld: public Fastcgipp::Request<char> {
-
public:
-
bool response()
-
{
-
out << "<html><body>";
-
out << "Hello world!";
-
out << "</body></html>";
-
return true;
-
}
-
}
-
main(){
-
try
-
{
-
Fastcgipp::Manager<Helloworld> fcgi;
-
fcgi.handler();
-
}
-
catch(std::exception& e)
-
{
-
error_log(e.what());
-
}
-
}
可以看到基本的只要从 Fastcgipp::Request
Popularity: 8% [?]