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

Abierto
#296 1 comentario 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
php

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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?
Lenguaje dominante
PHP
Estrellas
726
Forks
35
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de libvips/php-vips

Todos los issues de libvips/php-vips

Issues similares

Más issues de PHP

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.