web app.?!

Pages: 12
Hello.Is it possible to makee my C++ program a web app.?!
I am running Ubuntu 10.4 LTS
Last edited on
Hello.Y dun rly no wat u mean cn u xplane bttr.?!
kthxbye.
Sure. What kind of web-app?
Sure. What kind of web-app?

a web server;A coference managing system
Definitely. You'd need to read up on sockets.
Definitely. You'd need to read up on sockets.

where do I begin?
closed account (EzwRko23)
WebApp in C++? You must be joking.
You can, but it is not worth the trouble.
If you have an already made program in C++, provide a C-API to it and write a PHP/Python/Ruby/Java/whatever wrapper for it to implement a web-app frontend. If you start from scratch just use one of these languages. C++ is not for web-apps. Definitely.
hooshdar3 wrote:
where do I begin?

Socket programming is not trivial. But if you want to build a server, then that's what you'll need. There are many tutorials on the net like this one: http://www.linuxhowtos.org/C_C++/socket.htm

However there are other routes you can take without building your own server. You could consider CGI where your C++ programs are launched from a general purpose web-server like Apache. They run as basic console apps receiving the brouser request from std::cin and posting the returned web page to std::cout.

Here is some info on using CGI: http://www.purplepixie.org/cgi/howto.php
Note, there is no reason to use printf() in C++ you can just use std::cout
Last edited on
closed account (EzwRko23)
CGI is dead slow. Evel old, dead slow, interpreted Java 1.0 is a rocket compared to it.
Last edited on
xorebox, I have ubuntu, but so far found no Java IDE
You can use http://eclipse.org for a Java IDE, you will need to download the JDK separately. I assume Ubuntu has a package for that. Otherwise you could get one from Sun er... I mean Oracle.

With respect to CGI, using C++ would be very much quicker than an interpreted language like PHP or Python that need to load the interpreter before running the script.

But it really depends on your needs and your current software. There are many ways to webify application code and they all have different strengths and weaknesses.
Last edited on
I installed eclipse, but how to use it?it's a big problem!!

With respect to CGI, using C++ would be very much quicker than an interpreted language like PHP or Python that need to load the interpreter before running the script.


This used to be true but nowadays, there are interpreter that are "embedded" within the web server. Mod_Perl is one classic example. The Perl interpreter is not run every-time a Web Request came in.

To webify C++ programs are too tedious. Use the web friendly language (e.g PHP, Java, Perl etc) to wrap the C++ programs would be easier.

Socket programming is quite low level and there are a lot of Open Source HTTP servers around. Resort to socket programming when one intend to have their own customized protocol instead! This is definitely not for the faint-hearted as just designing the customized protocol is already a uphill task!
closed account (EzwRko23)

With respect to CGI, using C++ would be very much quicker than an interpreted language like PHP or Python that need to load the interpreter before running the script.


Oh, RLY? The interpreter is loaded once with the start of the webserver. In CGI, the whole program is loaded and dynamically linked with every request. This time is proportional to the size of the program, and even for small programs it is not negligible (0.1s is a huge amount of time). CGI is definitely not the way to go.
Last edited on
xorebxebx wrote:
The interpreter is loaded once with the start of the webserver.

But the program is not. So the interpreter still needs to load the program from disk. Then, on top of that, its an interpreter, not native code.
xorebxebx wrote:
In CGI, the whole program is loaded and dynamically linked with every request.

There are C++ solutions that mitigate this.

Here are some benchmarks for the same search engine using different languages:

http://www.wrensoft.com/zoom/benchmarks.html

C++ does extremely well here:
wrensoft wrote:

On average, the PHP version is faster than the ASP version, while the CGI (C++) version is more than 10 times faster than both PHP and ASP.

The PHP version is only slightly faster than the ASP version for smaller sites, but as the size of a site grows, the difference increases. This indicates that the PHP version scales better than the ASP version.

The CGI (C++) version performs the best and scales significantly better than the other versions as the size of a site increases (up to 70 times faster in some cases). The native ASP.NET Server Control also performs well. They are the only platform capable of searching through an enterprise size site of over 65,000 pages (as demonstrated in the "large site" test).


But for many purposes the speed difference will be unnoticeable. It rather depends what kind of work the program does after it has been loaded. Also it depends on how the program is to be used from the web. Is it a high traffic/do little app or is it a low traffic/do much app?

There are many issues governing the right solution for webifying an application. If the application is currently written in C++ then you need to weigh up the benefits of wrapping that up in another language. If the required web-interface is relatively simple then it may not make much sense to divide the skill-set between two languages. If the required web-interface is complex, then you might want to be able to draw on the large number of skilled PHP programmers developing web-applications.

It all depends on what you currently have and what you want to achieve.
closed account (EzwRko23)

But the program is not. So the interpreter still needs to load the program from disk. Then, on top of that, its an interpreter, not native code.


Depends on the size of the program and how CPU intensive it is. Loading from disk is rarely a bottleneck - usually OS is good at caching things. The problem in CGI is linking and creating a new process - the larger the program, the more time it takes to link it with the system libraries. There is lot of CPU cycles that go to waste, if your request just uses a 5% of that code.

For light, non CPU intensive tasks, but large programs (lots of libraries used only sometimes), the time to load a large executable may be huge compared with the time of interpreting of the small part of the code that is already in memory (and linked). Besides, if you really need performance, you should use ASP.NET or Java - which run native code. They are capable of handling thousands of requests per second. This is not possible for CGI (write a hello world program and test how many times per second is your OS able to load and run it).

Besides performance, you shouldn't be using CGI for security reasons. It is very easy to create a vulnerable C/C++ app.
Last edited on
xorebxebx wrote:
For light, non CPU intensive tasks, but large programs (lots of libraries used only sometimes), the time to load a large executable may be huge compared with the time of interpreting of the small part of the code that is already in memory (and linked).


It all depends on the nature of the application in question. But it is a terrible over-generalization to say this:

xorebxebx wrote:
C++ is not for web-apps. Definitely.


Or much worse this:

xorebxebx wrote:
CGI is dead slow. Evel old, dead slow, interpreted Java 1.0 is a rocket compared to it.


This is non-sense. You can code slow C++/CGI certainly, linking to extraneous and bloated libraries - just as you can code fast or slow Java, or Python, etc. But this statement goes way over the top to generalize. I've coded many C++ based CGI's and you can strip it down to its core necessities and there's no way it would be slower than the overhead in the abovementioned languages (which is much more significant than most people realize). If you're a bad C++ programmer, then yes, you can make a CGI slower than Java 1.0.

To give it context: EBay, Google and Yahoo are still all running C++ CGI's.

Ultimately, most web applications center around common usages that many higher level languages like Ruby, Python, etc. cater for and it certainly makes it easier to develop with. And the overhead is negligible in many (not all) situations.

But there is no denying that you can do more in C/C++, and given the effort, you can implement something that is better performing than a scripted counterpart.

Whether or not this effort and flexibility is necessary (or noticable) depends on the requirements of the project.

xorebxebx wrote:
Besides, if you really need performance, you should use ASP.NET or Java - which run native code. They are capable of handling thousands of requests per second. This is not possible for CGI (write a hello world program and test how many times per second is your OS able to load and run it).


It is absolutely possible, you can implement it as FastCGI.
Last edited on
NO! Why on this earth did you have to revive this?

Sorry, but you should've ignored him. xorebxebx hates C++ for some reason that I think I shrewdly can understand. Most of us try to ignore him, and I recommend you do too if he gets on your nerves for any reason. ;)

Good evening.

-Albatross
closed account (EzwRko23)

no way it would be slower than the overhead in the abovementioned languages (which is much more significant than most people realize)


It can be. C++ can't do many server side multithreaded optimizations like Java can. Lock elision / lock coarsening / cross-module inlining anyone? E.g. Tomcat is written 100% in Java and is faster than Apache: http://www.oreilly.com/catalog/9780596101060/chapter/index.html


It is absolutely possible, you can implement it as FastCGI


Possible but pointless. Add a small memory leak to it and your app is dead after a few days of operation.

@Albatross: C++ is fine as a game development language or OS language. But not web-app programming language.
Last edited on
Albatross wrote:
Sorry, but you should've ignored him. xorebxebx hates C++ for some reason that I think I shrewdly can understand. Most of us try to ignore him, and I recommend you do too if he gets on your nerves for any reason.


I didn't realize that, but I can somewhat see it now. Funny forum to be in with that idea though.

@xorebxebx: Talk about mis-quoting. You ripped out half of my sentence to make me imply something I never said, just so you can disagree with it. I already said you can code slow C++. I said if you code carefully and strip things down to its bare necessities, you can avoid the overhead - which is simply not a possible option with Java. (p.s. Tomcat was only proven to be faster than Apache in some certain scenarios, certain static files of particular file sizes, certain configurations. There are other scenarios Apache outperform Tomcat - you're jumping to conclusions and making false statements).

As has been said before, it's all about the right tool for the right job. Be open to the needs of the situation and understand the pros and cons to every tool.

To claim any universal rule like "C++ is never suitable for web app programming" just exposes your bias and hinders your ability to make the best choice.

Remember kids, Don't Do What Johnny Don't Does.
Pages: 12