tags:

views:

66

answers:

4

Hi, is it possible to call C function from 3rd party C library from a PHP5 script. If so any link or how to do it please.

Thanks

A: 

If you want to execute C source-code, than it's impossible. But you can compile that code and run it from within PHP using system().

Crozin
+4  A: 

You can also write PHP extensions in C. Put very simply, an extension lets you write a function (or functions) in C, then call those functions from PHP.

This Zend article is a good introduction.

Mark Biek
+1  A: 

There is a way to do it, but it's probably not a very good idea. One could write a small native program around the library (an executable for your system, that is). Then, you could use the php system() function to call that program. Then, read the output you need (if any) off the standard output?

(there may be a better way, I'm not super-familliar with PHP, but at least this should work.)

camperdave
+1  A: 

PHP is written in C, so if you have some C code that you want to be able to call in PHP, the best solution is to write a PHP extension, which will allow you to expose the functionality via some new php functions.

It's been a long time since I did this, but PHP has some tools to set up the skeleton of an extension. A good place to start is probably the official documentation

timdev