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

Đang mở
#296 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Sôi nổi
Công nghệ
php
Lĩnh vực
backend, performance

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?
Ngôn ngữ chính
PHP
Star
726
Fork
35
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của libvips/php-vips

Tất cả issue của libvips/php-vips

Issue tương tự

Thêm issue về PHP

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.