One of my friends had called up today. He has a project assignment in his company in which he needs to access and manipulate c++ code from within his php script. As we were brainstorming and trying to find ways to do this, some ideas crossed our mind.

1) To call the executable c code from php using function calls like system or ~~.

2) To compile the c code and make it into a php extension. This way, he can call methods in the code and use its objects.

We found one tool which is helpful in developing these extensions. That is SWIG. SWIG is a compiler that takes C declarations and turns them into the “glue” needed to access them from common scripting languages including Perl, Python, and Tcl. SWIG usually requires no modifications to existing C code and can often be used to build a working interface in a matter of minutes.

http://www.swig.org/Doc1.1/HTML/Introduction.html#n1

Though this seems quite an interesting option, he was a little hesitant because he was not sure whether the c++ code would have been written in such a way to act as a stand alone library.

3) To turn over to python. I have heard that in python, one can include c++ code and get down to the nuts and grits of any API.

Though this was a mundane 5 minute conversation, I found that it offered enough scope to look into one weak-area of PHP. Does anyone have any expertise in such a area? Like accessing native API code from scripting languages?

Any thoughts, inputs are welcome.

Advertisements