Overview of PHP FFI
FFI (Foreign Function Interface), introduced in PHP 7.4, allows PHP to call functions and use data structures from dynamic libraries (.dll on Windows, .dylib on macOS, and .so on Unix-like systems) without writing a full PHP extension.
Caveats:
- Security/Stability: FFI operates at a low level and can cause memory leaks, IO leaks, or compromise the operating system if used incorrectly.
- Performance: Accessing data structures via FFI can be slower (potentially 2x or more) than accessing native PHP arrays or objects, though it may use less memory in some cases.