Convert PHP to C++ code
Maybe I don't fully grok the context of why you think you need to do this, but I don't think the reasons you posted are particularly compelling.
Not very many web apps are CPU-bound, so I don't think you'll be impressed by the boost in performance. Compiling it down to native code isn't going to make your I/O or DB waits any shorter. There are better ways to scale a web app than moving to C++, and most of them involve reducing the time your script is waiting for data from the DB or disk (such as sharding your DB or moving data into a RAM cache).
Are the library dependencies really that much of an issue? Many of the most popular libraries are bundled with the PHP core now, plus any additional ones are generally a cinch to install. Once you've got 'em, you don't touch 'em, so I'm not sure why this is a particularly compelling reason to move to C++.
This is actually a very BAD reason to move to C++. Most shared hosting environments will let you run scripts in a PHP environment, but very few to none (unless you're looking at a VPS) will let you run an arbitrary binary like you'll have with a C++ app. There are better ways to control source readability in shared environments, like using file permissions correctly. If you're worried about clients stealing your PHP code, well, too bad. You can try to obfuscate it all you want, but it's generally pointless at the end of the day.
What specific C++ features do you so desperately need that PHP does not offer? To be honest, the idea of your average PHP coder mucking about with pointers and memory allocation scares the sh*t out of me. There are very good frameworks available for PHP, and I'd suggest you completely exhaust all of those options before you turn to changing the language of your entire code base just for some features you like in particular framework.
You mentioned cross-platform compatibility in your comment... PHP is honestly going to make this easier than C++ is. The PHP implementation is relatively standardized across platforms (except for a few lower-level functions) whereas you are likely going to be using a different compiler and system calls in C++.
This might also get interesting in a short while:
https://developers.facebook.com/blog/post/2010/02/02/hiphop-for-php--move-fast/
It's what keeps facebook alive ;) A technology that translates & compiles php to C++ and is going to go open-source. I expect it to be really well tested.
After much research, I've found http://www.phpcompiler.org/doc/maketea.pdf and http://rosecompiler.org/ROSE_Tutorial/ROSE-0.9.4a-Tutorial.pdf . Since PHP source code can be parsed and then translated to XML, converting it to C++ is just a matter of XSLT. Moreover, PHPCompiler also supports plugins and various transformations of source code (based on AST transformations). I think that should be sufficient for now.
Some extra references:
- http://rosecompiler.org
- http://rosecompiler.org/ROSE_UserManual/ROSE-UserManual.pdf
Thanks, everyone for participating in the discussion!