How can I use C++ code to interact with PHP?

qodeninja picture qodeninja · Oct 1, 2009 · Viewed 39.2k times · Source

I was reading somewhere that sometimes PHP is simply not fast enough and that compiled code has to sometimes "do the heavy lifting"

What is the api in C++ to do this?

Answer

Pascal MARTIN picture Pascal MARTIN · Oct 1, 2009

You can add functions/classes to PHP, programmed in C (and you can wrap a C++ class from C, if I remember correctly from an article I read some time ago), which might allow you to do some things faster -- if programmed well : no need for interpretation of PHP code ; only execution of machine code, which is generally way faster.

To do that, you'll have to develop a PHP extension.

There are not that many resources available on the Internet about that, but these one might help you to start :

And, specifically about the C++ part, this one might help too :

If you are really interested by the subject, and ready to spend some money on it, you could also buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; I've seen a couple of times that it was the book to read when interested on this subject (In fact, I've bought it some time ago, and it's an interesting read)

By the way, the author of that book is also the author of the first four articles I linked to ;-)