Skip to content

Instantly share code, notes, and snippets.

@Crell
Last active December 19, 2019 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crell/824ca3550aa8c7c9a9059cfb3fa43b2a to your computer and use it in GitHub Desktop.
Save Crell/824ca3550aa8c7c9a9059cfb3fa43b2a to your computer and use it in GitHub Desktop.
$ php -d ffi.enable=preload -d opcache.preload="dummy-preload.php" dummy-test.php
PHP Fatal error: Uncaught FFI\Exception: Failed loading scope 'DUMMY' in /home/crell/temp/php-ffi-test/dummy.php:11
Stack trace:
#0 /home/crell/temp/php-ffi-test/dummy.php(11): FFI::scope()
#1 /home/crell/temp/php-ffi-test/dummy-test.php(7): Dummy->__construct()
#2 {main}
thrown in /home/crell/temp/php-ffi-test/dummy.php on line 11
<?php
declare(strict_types=1);
FFI::load(__DIR__ . "/dummy.h");
opcache_compile_file(__DIR__ . "/dummy.php");
<?php
declare(strict_types=1);
require_once "dummy.php";
$d = new Dummy();
$d->printf("Hello %s!\n", "world");
#define FFI_SCOPE "DUMMY"
#define FFI_LIB "libc.so.6"
int printf(const char *format, ...);
<?php
declare(strict_types=1);
//FFI::load(__DIR__ . "/dummy.h");
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);
}
}
$ php -i | grep ffi
/etc/php/7.4/cli/conf.d/20-ffi.ini,
ffi.enable => preload => preload
ffi.preload => no value => no value
PWD => /home/crell/temp/php-ffi-test
$_SERVER['PWD'] => /home/crell/temp/php-ffi-test
$ php -i | grep opcache
Additional .ini files parsed => /etc/php/7.4/cli/conf.d/10-opcache.ini,
opcache.blacklist_filename => no value => no value
opcache.consistency_checks => 0 => 0
opcache.dups_fix => Off => Off
opcache.enable => On => On
opcache.enable_cli => Off => Off
opcache.enable_file_override => Off => Off
opcache.error_log => no value => no value
opcache.file_cache => no value => no value
opcache.file_cache_consistency_checks => 1 => 1
opcache.file_cache_only => 0 => 0
opcache.file_update_protection => 2 => 2
opcache.force_restart_timeout => 180 => 180
opcache.huge_code_pages => Off => Off
opcache.interned_strings_buffer => 8 => 8
opcache.lockfile_path => /tmp => /tmp
opcache.log_verbosity_level => 1 => 1
opcache.max_accelerated_files => 10000 => 10000
opcache.max_file_size => 0 => 0
opcache.max_wasted_percentage => 5 => 5
opcache.memory_consumption => 128 => 128
opcache.opt_debug_level => 0 => 0
opcache.optimization_level => 0x7FFEBFFF => 0x7FFEBFFF
opcache.preferred_memory_model => no value => no value
opcache.preload => no value => no value
opcache.preload_user => no value => no value
opcache.protect_memory => 0 => 0
opcache.restrict_api => no value => no value
opcache.revalidate_freq => 2 => 2
opcache.revalidate_path => Off => Off
opcache.save_comments => 1 => 1
opcache.use_cwd => On => On
opcache.validate_permission => Off => Off
opcache.validate_root => Off => Off
opcache.validate_timestamps => On => On
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment