lisachenko / z-engine

:zap: PHP Engine Direct API
MIT License
448 stars 22 forks source link

Did you get `FFI::load()` to work in preload? #37

Closed rask closed 4 years ago

rask commented 4 years ago

https://github.com/lisachenko/z-engine/blob/45b06747a7e8163e468e3ac83b0c0859740dafd8/src/Core.php#L266

I could not get FFI::load() to work in preload. Have you tested this and verified that it works? What does your php.ini opcache and ffi config look like for a working preload setup?

The problem in my tests is that opcache.preload requires opcache.preload_user to be set, which in turn disables FFI::load() if set. Which in turn means I have to manually set header.h in the ffi.preload INI config.

The aim would be to have FFI::load() inside preload, and FFI::scope() outside preload.

lisachenko commented 4 years ago

Quick question: what is your target OS platform? If it is Windows, then preloading is broken there (and as of 7.4.2 it was disabled). And if it isn't Windows, we still need to wait for 7.4.3 to have several fixes related to preloading and opcache.

See https://bugs.php.net/bug.php?id=79128.

lisachenko commented 4 years ago

I have tested preloading prior 7.4.2 and was managed to make it working, but tricky and unstable. Let me check if it is broken now or not...

lisachenko commented 4 years ago

Ok, it is working under Unix, version PHP 7.4.3-dev. My configuration is following:

[opache]
zend_extension=opcache.so
opcache.validate_timestamps=0
opcache.enable_cli=1
opcache.enable=1
opcache.preload=/path/to/z-engine/preload.php

[ffi]
ffi.enable=preload
rask commented 4 years ago

I'm on Ubuntu and latest available PHP from deb.sury.org.

Strange. For me that does not work. PHP requires me to set opcache.preload_user. And after I set opcache.preload_user I get errors about FFI::load() being disabled if opcache.preload_user is set. It says I need to add a header file path into ffi.preload.

Need to investigate. Are you running PHP-FPM/pools as root? I'm not using 7.4.3-dev so need to try that out also in case something's changed.

Thanks! Sorry for a tad off-topic question.

rask commented 4 years ago

Hello again.

Solved. opcache.preload with FFI::load() works when running the PHP-FPM master process as non-root. deb.sury.org PPA and similar often install PHP-FPM using root as the process manager user.

Things also work normally when running the built-in web server.

Thanks again, and sorry for the noise.