Fog Creek Software
Discussion Board




C to PHP

I have some C code I need to get into a PHP web page.

It's enough for rewriting to be a fair chunk of work (deterring me for now, but I'll bite the bullet if I have to)

The code basically is a routines which do some math and string manipulations and generate a result

Any ideas?

S. Tanna
Wednesday, July 30, 2003

I don't have a manual handy, but doesn't PHP allow you to call C code?  Or Python code?  You could write some wrappers that would allow you to continue using the C code in C and just return the data to PHP...

Sam Livingston-Gray
Thursday, July 31, 2003

You could run your C program via cgi.

Mike
Thursday, July 31, 2003

You can use the system command in PHP to call a C or any type of program. It will run in it's own shell so you need to be careful about filtering out possible mete-characters.

Matthew Lock
Thursday, July 31, 2003

... I mean "meta-characters".

Matthew Lock
Thursday, July 31, 2003

Check out SWIG from swig.org.
We used it on our web application to do some things that were slow in PHP as well as interface with our backend systems and it worked quite nicely for this kind of thing.

Matt Lee
Thursday, July 31, 2003

Wrap your C code in a PHP extension, then call the C code from PHP like any other PHP function.

dmooney
Thursday, July 31, 2003

PHP can call DLLs right?  Wouldn't that be a solution?

Lee
Thursday, July 31, 2003

I'm writing a hosted site, I think with a Unix O/S, but this might change.  I wonder if there is anything like a translator or cross compiler?  Even if imperfect and partial, this would suit me better than calling out to C code.

S. Tanna
Thursday, July 31, 2003

The best solution is going to be to re-write the C code in PHP, or move the C code to a C based CGI.  Of the two, the CGI will have better execution time on a UNIX system, and be easier to maintain.

Drop a line if you need some pointers on C based CGI programming.  It's a lot easier than you would think.

Clay Dowling
Thursday, July 31, 2003

*  Recent Topics

*  Fog Creek Home