I have a performance intensive routine that is written in PHP that I'd like to port to C++ for a performance increase. Is there any way to write a plugin or extension or something using C++ and interface with it from PHP? WITHOUT manually editing the actual PHP source?
Join them; it only takes a minute:
|
|
I've written a PHP plugin in C++ with the help of SWIG. It's doable, but it may take a while to get used to the SWIG-compilation cycle. You can start with the SWIG docs for PHP. Update |
||||
|
|
|
As Remus says, you can extend PHP with C/C++ using the Zend API. The linked tutorial by Sara Golemon is a good start, and the book Extending and Embedding PHP by the same author covers the subject in much more detail. However, it's worth noting that both of these (and pretty much everything else I found online) focus on C and don't really cover some tweaks you need to get C++ extensions working. In the
Any C++ library compile checks in the
EDIT - and here's how to specify g++:Last, and not least, in order to choose the C++ rather than C compiler/linker when building the extension, the 6th parameter to
From the PHP build system manual, the parameters are:
Presumably there's an automake command that would make this hack unnecessary. |
|||||||||||||||||
|
|
PHP itself a collection of loosely related libraries. See http://devzone.zend.com/article/1021 for a tutorial how to write your own. |
|||
|
|