Add support for `ffi.enable=preload` to php-vips in web environments
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Feature
- Klarheit
- Muss geklärt werden
- Aktivitätsstatus
- Aktiv
- Tech-Stack
- php
- Bereich
- backend, performance
Rechercherichtung
Read the issue’s discussion of ffi.preload, opcache.preload, and the FFI::scope() fallback alongside the existing FFI::cdef() path. The issue does not name repository files or tests; first locate init() and the current FFI setup, then decide how header generation and version matching should work. Done means agreeing on the proposal’s design and addressing its startup risk, FrankenPHP behavior, and Windows limitation.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
Background
#292 made CLI usage work with ffi.enable=preload, but PHP-FPM still requires ffi.enable=true, which allows any PHP code in the process to call arbitrary native libraries.
PHP allows FFI calls from code compiled through opcache.preload. However, calling FFI::load() in a preload script throws an exception when starting as root with opcache.preload_user. Dmitry Stogov recommends ffi.preload instead in php-src#4842.
Proposal
I have a working prototype that:
- Generates glib, gobject, and vips headers for the installed libvips version.
- Loads them via
ffi.preloadand compiles php-vips classes viaopcache.preload. - Tries
FFI::scope()ininit(), falling back to the existingFFI::cdef()path if unavailable.
Testing
With the official php:8.4-fpm image (root master, www-data workers), I sent 80 requests with worker recycling enabled. All succeeded with ffi.enable=preload, including requests handled by replacement workers. Existing tests also passed.
In FrankenPHP (ZTS), scopes loaded through ffi.preload weren't visible to worker threads, but the cdef() fallback worked from classes compiled through opcache.preload.
Limitations
Headers need to match the installed libvips version and should be regenerated when it changes. If a header declares a function that the installed library doesn't provide—for example, after downgrading libvips—PHP itself fails to start with Unable to start FFI module.
Windows would still require ffi.enable=true, since opcache.preload isn't supported.
Questions
- Would you be open to a PR for this?
- Should header generation be a
vendor/bincommand or a PHP function? - Is the startup-failure risk from mismatched headers acceptable for an opt-in feature?
- Vorherrschende Sprache
- PHP
- Sterne
- 726
- Forks
- 35
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus libvips/php-vips
-
Add MacPorts supportOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 48/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 25/100
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
-
Color QuantizationOffen
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 30/100
-
Schwierigkeit 5/5 Über eine Woche Anfängerfreundlichkeit 20/100
Alle Issues in libvips/php-vips
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 77/100
Adyen/adyen-magento2#3453 ·
Maintainer antworten meist innerhalb von 8 Tagen
-
component/media domain/discovery
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag
-
bug docker
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 1 Tag