Per this post here there are 3 ways
- (1)do the whole thing in C++, making your program a standalone web server (possibly proxying through apache to provide things like ssl, static media, authentication etc.)
- (2)run C++ in a cgi-bin, through apache
- make a PHP wrapper that shells out to the C++ part (this is a nice option if the performance-critical part is small, as you can still use the comfort that PHP’s garbage collection and string manipulation gives you)
I’m not sure which is best so I looked at what a high volume site does. Here is a post from Facebook in 2010
They use a static analysis tool Hip Hop, to convert PHP to C++.
I don’t need the static analysis tool as I only have about 1500 lines and can convert by hand…but I need a starting point.
Right now I run a Lamp stack and want to stay on it minus the (P)HP.
Here is a link that explains how Facebook works. Not sure how accurate it is.
Thanks
As the comments note, Facebook is almost certainly using a highly-customized solution that involves high administration costs in return for very high efficiency. It is unlikely that this is actually what you want.
Since what you want is simply to replace the “P” in your LAMP stack, that implies that you probably want to keep the “LAM” — the Linux, Apache, and MySQL (if relevant) parts. That’s a good idea; while there are advantages at Facebook’s scale to running a custom web server, it is extremely unlikely that it will actually be useful for you, and continuing to run Apache is certainly much easier and simpler. (And probably more secure, since you don’t have to think about the security and fix bugs all by yourself.)
And you’re planning to translate all your PHP, not just part of it, so calling C++ from PHP doesn’t make sense.
Thus, in your case, the best solution is most likely to be running the C++ application via cgi-bin with your existing Apache server.