| Author |
Calling C functions in PHP
|
|
| bjorn2k@hotmail.com 2005-11-28, 3:55 am |
| Hi all,
Is there a way to call functions written in C with PHP? A sort of JNI
but than for PHP.
greetz Bjorn
| |
| Michael Vilain 2005-11-28, 7:55 am |
| In article <1133163671.187780.239280@o13g2000cwo.googlegroups.com>,
bjorn2k@hotmail.com wrote:
> Hi all,
>
> Is there a way to call functions written in C with PHP? A sort of JNI
> but than for PHP.
>
> greetz Bjorn
Since php isn't compiled, how would that work, specifically? There'd
have to be some facility to call shared libraries and initialize them
and it probably wouldn't be portable.
You can call programs and pass them parameters via system() or
passthru() or use the COM object on Windows boxes. But I think calling
C functions in php would require linking said functions into mod_php or
the php interpeter. Perl has been doing this for years with CPAN
modules. Haven't seen the equivalent in php. Most of the add-on code
in PEAR is php code.
--
DeeDee, don't press that button! DeeDee! NO! Dee...
| |
| Sjoerd 2005-11-28, 7:55 am |
| You can write a SOAP webservice in C and then call it using PHP. You
can also use a external program, as Michael wrote above. You could also
make your own PHP module with the functions in it. Why do you want to
call C functions within PHP?
| |
| David Wahler 2005-11-28, 7:55 am |
| bjorn2k@hotmail.com wrote:
> Is there a way to call functions written in C with PHP? A sort of JNI
> but than for PHP.
You probably want a PHP extension. See
http://www.php.net/manual/en/zend.creating.php for details.
-- David
| |
|
|
|
| bjorn2k@hotmail.com wrote:
>
> Is there a way to call functions written in C with PHP?
Yes. You need to wrap your C functions into a PHP extension.
Cheers,
NC
| |
| bjorn2k@hotmail.com 2005-11-29, 6:57 pm |
| Thanks for the information. By the way, i want to call functions from
an existing API written in C from PHP to display it using a web
application.
--
Bjorn
| |
| Anonymous 2005-11-29, 6:57 pm |
| bjorn2k@hotmail.com wrote:
>
> Thanks for the information. By the way, i want to call functions from
> an existing API written in C from PHP to display it using a web
> application.
If you are using Windows and the API is contained within a DLL (which is
often the case) then you could call it via rundll32, which you can call
via the PHP system() function.
system('rundll32.exe YourAPI.DLL,FunctionWithinDLL Parameter1 Parameter2
....')
Bye!
|
|
|
|