A web developer’s diary

June 25, 2008

Accessing C or C++ code from PHP

Filed under: PHP — Celia @ 4:48 am
Tags: ,

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

1 Comment »

  1. Python is very hard to understand 😦

    Comment by Ficho — January 1, 2011 @ 8:45 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: