array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'ffi.examples-complete.php', 1 => 'A Complete PHP/FFI/preloading Example', ), 'up' => array ( 0 => 'ffi.examples.php', 1 => 'Örnekler', ), 'prev' => array ( 0 => 'ffi.examples-callback.php', 1 => 'PHP Callbacks', ), 'next' => array ( 0 => 'class.ffi.php', 1 => 'FFI', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/ffi/examples.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
php.ini
ffi.enable=preload opcache.preload=preload.php
preload.php
<?php
FFI::load(__DIR__ . "/dummy.h");
opcache_compile_file(__DIR__ . "/dummy.php");
?>
dummy.h
#define FFI_SCOPE "DUMMY" #define FFI_LIB "libc.so.6" int printf(const char *format, ...);
dummy.php
<?php
final class Dummy {
private static $ffi = null;
function __construct() {
if (is_null(self::$ffi)) {
self::$ffi = FFI::scope("DUMMY");
}
}
function printf($format, ...$args) {
return (int)self::$ffi->printf($format, ...$args);
}
}
?>
test.php
<?php
$d = new Dummy();
$d->printf("Hello %s!\n", "world");
?>