int MIMEHeader() { cout << "Content-type: text/html" << endl << endl << endl; cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">"<<endl; cout <<"<HTML xlmns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>" <<endl; } int main() { MIMEHeader(); cout<<">head<>/head><body>"<<endl; cout<<"Hello World!"<<endl; cout<<"</body>"<<endl; return TRUE; }
The next step here is to get apache to proxy the output of our program to the end user's web browser. You'll need this block in your
<Directory "/path/your/website/x"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> ScriptAlias /x /path/to/your/website/x
At this point you're good to go, and boy is it FAST. In my non-exhaustive testing, a simple App involving a MySQL query takes less than 1ms more than the actual MySQL query. Obviously, your results may vary. Here's the example C++ I wrote for a start before I started adding more fancy api type features to it. I compiled it on CentOS 5.4 with stock CentOS distributed MySQL 5.1:
// Compile this using: // g++ -o mysqltest mysqltest.cpp -L/usr/lib64/mysql -lmysqlclient -I/usr/include/mysql && ./mysqltest //#include <iostream>#include <mysql/mysql.h>using namespace std;MYSQL *connection, mysql;MYSQL_RES *result;MYSQL_ROW row;int query_state;int MIMEHeader() {cout << "Content-type: text/html"<<endl<<endl<<endl<<"<HTML><BODY><PRE>";}int Footer() {cout << "</PRE></BODY></HTML>";}int main() {char * env;MIMEHeader();mysql_init(&mysql);connection = mysql_real_connect(&mysql,"localhost","myUs3r","myPa55word","myBookmarks",0,0,0);if (connection == NULL) {cout << mysql_error(&mysql) << endl;return 1;}query_state=mysql_query(connection,"select * from links where id like '%blogger.com';");if (query_state!=0) {cout << mysql_error(&mysql) << endl;return 1;}result = mysql_store_result(connection);cout << "<table>"<<endl;while (( row = mysql_fetch_row(result)) != NULL ) {cout << "<tr><td>" << row[0] <<"</td><td>"<< row[1] <<"</td><td>"<< row[2] <<"</td></tr>"<<endl;}cout << "</table>"<<endl;Footer();mysql_free_result(result);mysql_close(connection);return 0;}
No comments:
Post a Comment