I start with PHP for dynamic web pages. I have several libraries written in ANSI C for getting / setting parameters and other proprietary materials. I wonder if there is a simple solution to use a shell inside PHP to call these functions? Is there an existing class / library? What would be the best practice for this? I do not want to make calls to external applications and use stdin / stdout!
Is there a simple example? I donβt want to dig the Zend documentation now, I only need a sense of complexity.
Can you pack the libraries in a DLL? If so, you can call them through the PHP COM api.
PHP COM docs: http://us3.php.net/manual/en/book.com.php
Code example:
<?php $com = new COM("DynamicWrapper"); $com->Register("KERNEL32", "Beep", "i=ll", "f=s", "r=l"); $com->Beep(800, 10);
Otherwise, you can write an extension containing a custom wrapper function (i.e. execute_through_wrapper ('yourfunc')). Here is a document on writing php functions in C.
http://php.net/manual/en/internals2.funcs.php
Edit:http://abhinavsingh.com/blog/2008/12/php-extensions-how-and-why/
Here's a quick guide to writing extensions in C. It shouldn't be too hard to write a wrapper function. After creating the extension, it can be dynamically loaded via dl() (very dangerous and worthless).
dl()
http://us2.php.net/manual/en/function.dl.php
These are the only options in your case. There is no equivalent to linux (.so loader) dll bootloader (its associated win32 api call).
You can also use gearman as an intermediary.
Gearman provides a general framework application for working with other machines or processes that are better suited to the job. This allows you to do parallel work, load balance processing and call functions between languages. It can be used in various applications, from high-availability websites to replicating events database replication. In other words, it is the nervous system for distribution that processes messages.
What about SWIG? http://www.swig.org/
At http://pear.php.net/ I found an extension named "inline_c". Unfortunately, I do not support. But it seems that this will be the material that I would prefer.