views:

153

answers:

6

Hi guys, I want to experiment a bit with C++ as a server side language. I'm not looking for a framework, and simply want to achieve a silly old "Hello World" webapp using C++.

Is there an Apache HTTP server module that I can install?

If i can do the PHP equivalent of :

<?php 
    $personName = "Peter Pan";
    echo "Hello " . $personName;

I'd be most thrilled! Thanks in advance!

+7  A: 

cgi would do this. Just have your C++ app spit its output to stdout and your mod_cgi will handle it

yaya
I just stumbled across mod_fast_cgi, does that bare any relation to mod_cgi?
Joe Zephyr
+1  A: 

I'm not saying there is no such thing, but if there is it would be monumentally inefficient. C++ is a compiled language, not an interpretive one, so the putative Apache C++ module would have to invoke the C++ compiler to compile the code before executing it. This would be very, very slow, apart from other problems.

anon
I don't think he meant interpreted C++, just the C++ webserver equivalent of a hello world.
Georg Fritzsche
He asked if there was a mod_c++. By analogy with mod_php, mod_perl etc. this would be an Apache module that ran C++ code.
anon
The C++ will be pre-compiled for optimal performance. If interpreted is desired, I suppose PHP would suffice. :) I doubt C++ will be inefficient, as well written C++ (compiled) can be blistering fast.
Joe Zephyr
@Josamato Once compiled to an executable, it doesn't matter to Apache what language the executable was written in.
anon
I couldn't disagree with you more. Once compiled, it can serve as many requests as needed without a new recompilation, until the source file change. PHP and Python do the same, with the difference that it compiles to, caches and executes bytecode instead of a binary executables. It is possible and viable, and potentially much more efficient.
Juliano
+1  A: 

"mod_c++" doesn't make sense; Once you're talking about compiled programs, Apache doesn't care what language the binary comes from. mod_cgi allows Apache to invoke such a binary (regardless of it's source language) in response to HTTP requests. Read more here:

http://library.thinkquest.org/16728/content/cgi/cplusplus.html

meagar
+1  A: 

Suppose for the moment the OP wanted something that was "like mod_php, mod_perl". Given the right configuration, it would be monumentally easy for the "mod_c++" to look at the source files, and compiled files and decide whether it had to do a "one off" compilation task. In fact this is how make works.

I know the OP probably didn't mean that it had to be "interpreted", but it's certainly not impossible to allow apache to compile cpp files on the fly if needed [this is how jsp works, btw].

blah
I got a bit of my inspiration from JSP. Heck, I bet you could even get Apache to compile PHP if you wanted to increase performance etc. Who knows what's possible these days.
Joe Zephyr
A: 

I did create a mod_cpp once. It basically was written in c, but loaded a .so which was in turn written in C++.

Its performance was really good, but lacked a lot of things that we take for granted in things like PHP (sessions, HTML un/escaping, etc). It did use a template engine to separate the HTML from the C++.

I tell you, the initial set-up was a lot of work (the mod_cpp part); after that, it was kinda easy to write the .so's. I even tried to create an sf.net project to open-source it, but I never got around to actually porting it :-(

In summary: I did not find anything like that on the net, did it myself and found out to be a lot more work then I anticipated, but the result was very cool! This helped me a lot: Apache Modules

Gianni
I guess that's always the thing with software development, the task at hand is always a bit more involved than we think it is. :)
Joe Zephyr
Also about the HTML escaping, dangers of buffer overflow, XSS and SQL injection, these things will be time consuming until one has developed a comprehensive OOP library that deals with the commonalities.
Joe Zephyr
+2  A: 

You might want to have a look at http://www.webtoolkit.eu/wt or www.tntnet.org instead.

JoJo