We have a web application (quite a heavy-weight one) that does a whole bundle of stuff, web ui, mathematical processing and modelling, and database-related stuff.
A number of the processes that happen in PHP are quite slow, mostly because PHP sucks for mathematical processing.
In the future, we'd like to break these slow process off, and rewrite them in something faster, probably C++, or maybe Java.
Does anyone know of a generic way to get data in and out of PHP and into another language's environment? I've already considered serialising things into JSON and shovelling them into /dev/shm or a socket, then have the other language listen on a socket, or look at the shared memory location etc.
This kinda thing works fine for native types, but does suck quite hard when you consider that a lot of the stuff that gets passed around are actually class instances and similar objects.
I'm not sure of a sensible solution, but I've been considering Quercus PHP implementation which is pure Java, as well as the PHP/Java bridge.
However, I've been unable to find anything for C++ that would do a similar function. Writing a PHP module is a possibility, but I'm struggling to see how it could be sufficiently generic, and not just a case of rewriting each new (and some old) script into a module, then calling those functions in PHP.
Google protocol buffers
Protocol Buffers
What is it?
Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats.
<endquote>
It supports fast and efficient serialization for objects that you define in the .proto
language, and supports C++/Java natively, and PHP with a 3rd party add on.
Have a look at Gearman: http://gearman.org/
It works with C and PHP, amongst a heap of other languages. It doesn't explicitly state C++ though :(
Apart from working as a bridge, it can work as a load balancer and give system redundancy.
I haven't used it myself, but it seems pretty awesome :)
EDIT: Gearman would require you to serialize the data though, so a minus in that regard.
We are currently using zend framework to call C++ libraries in our php code. It might be what you are looking for.
Cheers!
I've recently stumbled upon the Hiphop optimizer. Facebook uses this, it might be just what you need,though i can't speak from experience. https://github.com/facebook/hiphop-php/wiki/
See if it suits your needs :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With