Add support for `ffi.enable=preload` to php-vips in web environments

Ouverte
#296 1 commentaire 1 réaction 0 personnes assignées Voir sur GitHub

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.preload and compiles php-vips classes via opcache.preload.
  • Tries FFI::scope() in init(), falling back to the existing FFI::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/bin command 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

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de libvips/php-vips

Toutes les issues de libvips/php-vips

Issues similaires

Plus d'issues PHP

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.