Re: FFI [was: Breakages with rc1]
| From: | Dusk | Date: | Thu, 07 Sep 2023 05:12:29 +0000 |
| Subject: | Re: FFI [was: Breakages with rc1] | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121003@lists.php.net to get a copy of this message | ||
On Sep 6, 2023, at 19:18, Hanz <zaunere@gmail.com> wrote:
> On a totally different note... I'm trying to get my head around FFI
> <https://www.php.net/manual/en/book.ffi.php> specifically
> how it could be
> used to orchestrate 3rd party pipelines, like those of python.
That isn't a particularly good use case for FFI. If you're trying to call Python scripts,
you're probably looking for popen(), proc_open(), or something like the Symfony Process
component (composer require symfony/process).
FFI allows PHP scripts to load and call functions in C libraries. This can allow PHP scripts to
access functionality which doesn't have PHP wrappers available.
If you're on macOS, here's a silly but functional example which calls the NSBeep()
function to make your computer beep:
$ffi = FFI::cdef(<<<'EOF'
void NSBeep(void);
EOF, "@rpath/AppKit.framework/AppKit");
$ffi->NSBeep();
sleep(1);
(Don't worry too much about the @rpath bit.)