Java – A universal bridge between C++ and PHP

A universal bridge between C++ and PHP… here is a solution to the problem.

A universal bridge between C++ and PHP

We have a web application

(quite a heavyweight application) that performs a whole set of operations, web UI, mathematical processing and modeling, and database-related operations.

Many of the processes that happen in PHP are very slow, mainly because PHP has poor math.

In the future, we hope to break these slow processes and rewrite them with something faster, maybe C++ or Java.

Does anyone know a generic way to transfer data in and out of PHP and into another locale? I’ve thought about serializing things to JSON and shoveling them into /dev/shm or sockets, then having other languages listen on the socket, or looking at shared memory locations, etc.

This kind of stuff works fine for native types, but it’s really bad when you consider that a lot of the things being passed are actually class instances and similar objects.

I’m not sure if there’s a sensible solution, but I’ve been thinking about Quercus PHP pure Java implementation, as well PHP/Java bridge.
However, I have not been able to find any C++ that can perform a similar function. It’s possible to write PHP modules, but I’m struggling to understand how it’s generic enough to not just rewrite every new (and some old) script into a module and then call those functions in PHP.

Solution

Google protocol buffers

Protocol Buffer

What is it?

Protocol Buffer is a way to encode structured data in an efficient and scalable format. Almost all of Google’s internal RPC protocols and file formats use Protocol Buffers.

It supports fast and efficient serialization of objects you define in the .proto language, and natively supports C++/Java and PHP with 3rd-party plugins.

Related Problems and Solutions