Add support for `ffi.enable=preload` to php-vips in web environments
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 35/100
- Type d'issue
- Fonctionnalité
- Clarté
- À clarifier
- Activité
- Active
- Stack technique
- php
- Domaine
- backend, performance
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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?
- Langage dominant
- PHP
- Étoiles
- 726
- Forks
- 35
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Aucun modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de libvips/php-vips
-
Add MacPorts supportOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 48/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 25/100
-
Difficulté 4/5 3-5 jours Accessibilité débutants 35/100
-
Color QuantizationOuverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 30/100
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 20/100
Toutes les issues de libvips/php-vips
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
Adyen/adyen-magento2#3453 ·
Les mainteneurs répondent en général sous 8 jours
-
component/media domain/discovery
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
Les mainteneurs répondent en général sous 1 jour
-
bug docker
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
Les mainteneurs répondent en général sous 1 jour