PHP: How To Call Standard Library Functions

前端 未结 4 1411
遥遥无期
遥遥无期 2021-02-09 02:27

I\'m starting with PHP for dynamic web pages. I have some libraries written in ANSI C for getting/setting parameters and other proprietary stuff. I wonder, is there a simple sol

4条回答
  •  日久生厌
    2021-02-09 03:22

    Can you package your libraries into a DLL? If so, you can call them through PHP's COM api.

    PHP COM Docs: http://us3.php.net/manual/en/book.com.php

    Example Code:

    Register("KERNEL32", "Beep", "i=ll", "f=s", "r=l");
    $com->Beep(800, 10);
    

    Otherwise you can write a extension that contains a custom wrapper function (ie, execute_through_wrapper('yourfunc')). Here is a doc 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 is a quick tutorial on writing extensions in C. It shouldn't be too difficult to write a wrapper function. Once you created the extension, it can be loaded dynamically through dl() (very dangerous, and depreciated).

    http://us2.php.net/manual/en/function.dl.php

    Those are the only options in your case. There isn't a linux equivalent (.so loader) of the dll loader (its a win32-related api call).

提交回复
热议问题