Open KEINOS opened 4 years ago
I can't make the FFI (Foreign Function Interface) work.
$ docker run --rm -it test:local php /app/sample.php Fatal error: Uncaught FFI\Exception: Failed loading '/usr/local/lib/php/extensions/no-debug-non-zts-20200804/libutil.so' in /app/sample.php:6 Stack trace: #0 /app/sample.php(6): FFI::cdef('void print(char...', '/usr/local/lib/...') #1 {main} thrown in /app/sample.php on line 6
<?php $util = FFI::cdef( "void print(char* p0); int sum(int p0, int p1);", "/usr/local/lib/php/extensions/no-debug-non-zts-20200804/libutil.so" ); $util->print( (string) $util->sum(2, 4) );
FROM golang:alpine AS builder RUN \ apk --no-cache add \ git \ gcc \ musl-dev \ && git clone https://github.com/eislambey/php-ffi-go-example.git /go/src RUN \ cd /go/src && \ GOOS=linux go build -o libutil.so -buildmode=c-shared util.go FROM keinos/php8-jit:latest USER root COPY sample.php /app/sample.php COPY --from=builder /go/src/libutil.h /usr/local/lib/php/extensions/no-debug-non-zts-20200804/libutil.h COPY --from=builder /go/src/libutil.so /usr/local/lib/php/extensions/no-debug-non-zts-20200804/libutil.so RUN \ apk --no-cache add \ libffi-dev \ # needs for "stddef.h" gcc \ # requirement for ld-musl-x86_64.so.1 musl-dev \ && chmod 0755 /usr/local/lib/php/extensions/no-debug-non-zts-20200804/libutil.*
php -i
$ docker run --rm test:local php -i | grep ffi Configure Command => './configure' '--build=x86_64-linux-musl' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-openssl=/usr' '--with-system-ciphers' '--with-ffi' '--enable-gd' '--with-external-gd' '--with-webp' '--with-jpeg' '--with-xpm' '--with-freetype' '--with-curl' '--with-libedit' '--with-zlib' '--with-pear' '--enable-soap' '--enable-pcntl' '--enable-opcache' '--enable-sockets' 'build_alias=x86_64-linux-musl' 'CPPFLAGS=' ffi.enable => preload => preload ffi.preload => no value => no value
$ docker run --rm test:local php -i | grep extension_dir extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20200804 => /usr/local/lib/php/extensions/no-debug-non-zts-20200804 sqlite3.extension_dir => no value => no value
So far, with libc.so.6, FFI seems to work. So the functionality of FFI might be OK.
libc.so.6
We better check the samples in the official doc one-by-one rather than using the Golang ones first.
I can't make the FFI (Foreign Function Interface) work.
php -i