Is it possible to use C++ binaries from php

前端 未结 8 1924
囚心锁ツ
囚心锁ツ 2020-12-01 08:00

Is it possible to write some C or C++ code and compile to binaries, then use those binaries with php? Is it also possible to write a php library using C and C++ ?

If

8条回答
  •  天命终不由人
    2020-12-01 08:37

    You might want to check out SWIG, a general tool for wrapping libraries so that they may be called from a variety of languages. PHP is supported by SWIG, as are Perl and Lua (the targets I've personally used). Quoting from the features list at the SWIG website:

    SWIG currently generates wrapper code for eighteen different target languages:

    • Allegro CL
    • C#
    • CFFI
    • CLISP
    • Chicken
    • Guile
    • Java
    • Lua
    • Modula-3
    • Mzscheme
    • OCAML
    • Octave
    • Perl
    • PHP
    • Python
    • R
    • Ruby
    • Tcl
    • UFFI

    In addition to this, the parse tree can be exported as XML and Lisp s-expressions. Experimental work is also available for a Pike module.

    Some of its features are dependent on back-end support in the per-language wrapper generators, but in general it provides easy to use wrappers for passing all plain-data value types in and out of functions. Where the target language has the concept, it can usually map object models as well.

提交回复
热议问题