2

I was wondering if there was a way to call existing C code from php?

Traker
  • 2,147
  • 3
  • 23
  • 38

2 Answers2

6

If your C code is compiled to an executable, that executable can be executed from PHP -- but I'm guessing this is not quite what you meant ?

If you want to excute C code from PHP : that is not possible... unless you compile your C code to a PHP extension.

A PHP extension is like a .dll, on windows : it's a library, that can export functions that can be called from PHP.


If you want to learn more about writing PHP extensions, those links will probably interest you :

And, if you are really interested by the subject, and ready to spend some money on it, you could buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; It's considered as the book to read when interested on this subject (In fact, I've bought it some time ago, and, in my opinion, it is indeed an interesting read)

BTW, the author of that book is also the author of the first four articles I linked to ;-)

chelmertz
  • 20,399
  • 5
  • 40
  • 46
Pascal MARTIN
  • 395,085
  • 80
  • 655
  • 663
1

This article talks about PHP-C++ bindings. May be of help. In particular, checkout the BEGIN_EXTERN_C/END_EXTERN_C macros.

dirkgently
  • 108,024
  • 16
  • 131
  • 187