Skip to content

Instantly share code, notes, and snippets.

@tvlooy
Last active January 21, 2019 22:17
Show Gist options
  • Save tvlooy/e657ec14e2dbcc0a0bd6f248a8834191 to your computer and use it in GitHub Desktop.
Save tvlooy/e657ec14e2dbcc0a0bd6f248a8834191 to your computer and use it in GitHub Desktop.
PHP FFI obsoletes pecl/pledge

PHP FFI obsoletes pecl/pledge

Example with pecl/pledge:

$ cat test_pecl.php
<?php

var_dump(count(scandir('/etc')));
unveil(__DIR__, 'r');
scandir('/etc');

$ php -dextension=pledge test_pecl.php
int(77)

Warning: scandir(/etc): failed to open dir: No such file or directory in /home/tvl/test_pecl.php on line 5

Warning: scandir(): (errno 2): No such file or directory in /home/tvl/test_pecl.php on line 5

Same example with (core extension) FFI:

$ cat test_ffi.php                      
<?php

$libc = FFI::cdef('
    int unveil(const char *path, const char *permissions);
', 'libc.so.92.5');

var_dump(count(scandir('/etc')));
$libc->unveil(__DIR__, 'r');
scandir('/etc');

$ php -dextension=ffi test_ffi.php      
int(77)

Warning: scandir(/etc): failed to open dir: No such file or directory in /home/tvl/test_ffi.php on line 9

Warning: scandir(): (errno 2): No such file or directory in /home/tvl/test_ffi.php on line 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment