17

On our embedded device, we currently use PHP for its web interface, and unfortunately it's quite slow. We've been experimenting with Python, but is seems (at least on FPU-less ARM architecture) to be as slow as PHP.

Therefore we're thinking about implementing web interface in some compiled language like C++, but so far the only thing we've found is Wt, which looks more like desktop than web framework and it's documentation is rather complicated for a beginner.

So my question is: do you know about any good web frameworks for C/C++? What would make me totally happy would be something like C++ Django, but I doubt such thing exists :-)

che
  • 12,097
  • 7
  • 42
  • 71
  • 2
    Have you done much string processing in C++? Since web programming is so much string processing, it would be a real pain. This is WHY PERL and PHP and the rest were created, because they are really good at the types of things web programming needs, and C++ just isn't. – Adam Jan 26 '09 at 16:19
  • 5
    I have done a lot of text processing with C++. Just use good libraries (Boost string algo, regex,...) and everything will be OK. – Nemanja Trifunovic Jan 26 '09 at 22:24
  • Hey, I've been working tirelessly on this very problem github.com/corvusoft/restbed. I'd love to see the community grow. – Ben Crowhurst Jul 23 '15 at 13:21

12 Answers12

11

What is the reason your site is slow in PHP? Have you profiled the code to figure out the bottle necks? Replacing the entire codebase with another language is likely to be too large a tool for the job.

Perhaps if some portion is computationally intensive, then maybe you can implement a PHP module in C++ to do the job.

spoulson
  • 21,335
  • 15
  • 77
  • 102
  • As far as I know most of the delays are caused by including files with classes that generate various components of the final page. – che Jan 26 '09 at 16:14
  • Are you sure? Even complex PHP frameworks only have a delay of a few MS when including their complex web of files, and if you're using a framework-less PHP then its likely to be even less. – ryeguy Jan 26 '09 at 16:38
  • On our mildly loaded XScale box, including stuff and creating the objects takes between 0.75 and 1.7 seconds. – che Jan 26 '09 at 17:01
  • I'm curious why you're using a minimal processor for a PHP web application server. Is this a mobile device? – spoulson Jan 26 '09 at 17:43
  • It isn't exactly pocket-sized. The key issue is the cost of the hardware. – che Jan 27 '09 at 00:04
10

You can take a look at CppCMS. I don't know how mature or good it is, but it sounds like what you are looking for.

Another option is to write the main application in Python/PHP and then rewrite the critical parts in C, which seems more sane to me.

HolySpirit
  • 101
  • 3
10

If I were you, I would give Wt a try. I don't think you will find another solution as complete and easy to use as Wt with similar performance. The mailinglist are active, and has regular posts of people who use it on embedded devices. The Wiki (here) of the project mentions some numbers for embedded deployment and performance on ARM.

user52875
  • 3,020
  • 22
  • 21
  • 1
    This accepted answer is quite old. Cppcms, which was a very good alternative then, has come up a long way since then. Check it out: http://cppcms.com/ – augustin Jun 01 '12 at 02:32
  • 1
    Excellent :-) Luckily Wt keeps evolving too: WebSockets, WebGL 3D, HTML5 video, server push, client SSL certificates, ... – user52875 Jun 08 '12 at 15:02
7

I had just seen this link as a referrer to CppCMS. Several questions/answers about it.

Q. How is it mature?
A. There is a Wiki 100% based on it. Developers blog runs on CppCMS as well. So you can see it quite works. well. At least for author.
Q. "What would make me totally happy would be something like C++ Django"
A. Actually it is "C++ Django". Many Ideas had been taken directly from Django, like forms, template inheritance and some more. So you would probably feel at home
Q. Nanogear
A. I had taken a look on it... It has many plans but not-too-much code.
Q. How many projects using it.
A. Not many. It is quite new project.
Q. Who am I?
A. To be honest I'm the developer of CppCMS.

6

Do you really need a web framework or just an html templating library?
See here for template options: C++ HTML template framework, templatizing library, HTML generator library

Community
  • 1
  • 1
Martin Beckett
  • 94,801
  • 28
  • 188
  • 263
  • Thanks for the link, templates are certainly heplful, but having something that would dispatch requests and provide nice API for HTTP requests and resposes would be nice as well. – che Jan 26 '09 at 16:17
  • I thought if you were in the embedded world you might want something light – Martin Beckett Jan 27 '09 at 02:51
4

One thing to look at here is using C++ for some sort of web service instead of an actual web app development environment. On one of my current projects we generate JSON(and parse for requests) then let the client(web browser) deal with the rest. You have a great deal of computing power available to you on the client machine, mix in some javascripty magic and boom, now your embedded device can go back to doing what its supposed to do. I personally kind of like Wt and think it is your best bet if you want to dev the whole "web app" thing in C++.

As to the specifics of how you get your C++ code to start serving up web services, you can use the amazing boost.asio library(they have an http server example) and json_spirit(I think its on codeproject)

Hippiehunter
  • 967
  • 5
  • 11
3

How about Nanogear. I haven't used it, so I'm not sure if it is a good fit. Here is a quote from the website.

C++ is a great, general purpose programming language but no modern, easy-to-use and powerful C++ web frameworks were made during these years. We try to fill the gap with Nanogear. Inspired by the Zend Framework and Rails we want to bring C++ to the web, easily.

Here is a link to the older googlecode site Google Code Nanogear Looks like there is more info there.

Philip Tinney
  • 1,986
  • 17
  • 19
2

Try Lua. There is Xavante embeded web server somewhere on LuaForge.

It's very fast, very small and very extensible - as all about lua is.

You have power to use Lua where scripting fits betteer, and use C++ functions where in need of more speed and conection to existing native code.

dmajkic
  • 3,448
  • 1
  • 18
  • 24
1

You can have a look at Tntnet. It uses its own template language which looks a bit like PHP, only with much more additional tags.

jplatte
  • 1,121
  • 11
  • 21
1

Check out the ffead c++ application framework (http://code.google.com/p/ffead-cpp/), its developed on the lines of Spring for JAVA.

Sumeet
  • 151
  • 1
  • 2
1

Since no one else has said it, I will. Try Java. Java is a compiled language with a good web framework. It is also very scalable. Every coperation I have worked for uses java as its main web-technology, and this is mainly due to this scalability factor. Not sure if it will work with your architecture, but it answers the question:

Are there any web frameworks for compiled languages like C++?

Alex
  • 6,843
  • 10
  • 52
  • 71
  • Java is hardly a compiled langauge. It compiles to byte code, and then the JVM interprets (or maybe JITs) it. – Sunny Milenov Jan 26 '09 at 16:33
  • Performance of java is almost 1:1 with C++ once the code has optimized. While it is true that bytecode isn't true native code compilation performance was the important point here. – Alex Jan 26 '09 at 16:39
  • Unless using very expensive development tools, java will be very slow on these ARM processrs. There are no byte-compiling JVMs available afaik (and even then, I expect byte-compiling on that architecture to be very slow too). – user52875 Jan 26 '09 at 22:15
  • Depends critically on the availability of Jazelle (HW accel for Java on ARM) – MSalters Jan 27 '09 at 15:11
1

You may give a try to embedded version of CppCMS.

It's quite new and exprerimental development but It looks like it is much more suitable then Wt because it is ore web oriented (more closer to Django) and not GUI like.

Artyom
  • 31,019
  • 21
  • 127
  • 215