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

オープン
#296 コメント 1 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
活発
技術スタック
php

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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?
主要言語
PHP
スター
726
フォーク
35
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

libvips/php-vips のほかの issue

libvips/php-vips の issue をすべて見る

似ている issue

PHP の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。