Foreign Function Interface (FFI)¶
Foreign Function Interface
, also known as FFI
allows loading external libraries, such as .DLL
or .so
, and access directly their function without writing a PHP extension.
<?php
// Extracted from the PHP manual
// create FFI object, loading libc and exporting function printf()
$ffi = FFI::cdef(
"int printf(const char *format, ...);", // this is a regular C declaration
"libc.so.6");
// call C's printf()
$ffi->printf("Hello %s!\n", "world");
?>
See also Blazingly Fast Markdown Parsing in PHP using FFI and Rust, PHPun with FFI: Getting Rust-ic