php / php/php-src

How to properly restart Apache(mod-php) when updating FFI_LIB libraries in ffi.preload

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

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

Extension: ffi Feature SAPI: apache2handler Status: Needs Triage
主要言語
C
スター
40.4k
フォーク
8.2k
平均マージ
2日 13時間
マージ済み PR(30日)
96

説明

Description

apache(prefork) 2.4.62
php 8.2.28

I already have a properly functioning FFI configuration with connected libraries.

My question is whether a complete restart of the Apache process (full stop and then start) is always necessary when the library (.so) needs to be updated.

Once, to update the library, I overwrote the file at the path specified by FFI_LIB with an updated file and tried apachectl graceful. I confirmed that all Apache worker processes restarted, but the result showed that it was still referencing the old library rather than the updated one.

After some experimentation, I found that when I changed the FFI_LIB path in the header (.h) file configured in ffi.preload and then tried apachectl graceful, it successfully referenced the new library.

However, when I examined pmap -p <APACHE PID>, I observed the following two mappings:

00007fcce5531000     20K r---- /home/abc/xyz.so.02
00007fcce5536000    252K r-x-- /home/abc/xyz.so.02
00007fcce5575000     52K r---- /home/abc/xyz.so.02
00007fcce5582000     12K r---- /home/abc/xyz.so.02
00007fcce5585000      4K rw--- /home/abc/xyz.so.02
...
00007fccf36bc000     20K r---- /home/abc/xyz.so.01
00007fccf36c1000    252K r-x-- /home/abc/xyz.so.01
00007fccf3700000     52K r---- /home/abc/xyz.so.01
00007fccf370d000     12K r---- /home/abc/xyz.so.01
00007fccf3710000      4K rw--- /home/abc/xyz.so.01

The Apache process was running normally, and the library functions were working properly, but I'm still unsure if this result is normal. If I were to update 100 times, would I end up with about 100 such mappings?

When using ffi.preload and needing to update the connected library, which of the following approaches is correctly understood?

  1. Use symbolic links for changes. (At least from what I've observed, this doesn't guarantee consistent behavior.)
    e.g.,

    xyz.so -> /home/abc/xyz.so.01 (symbolic link)
    xyz.so.01
    xyz.so.02
    
  2. Always change the FFI_LIB path in the ffi.preload header file.
    e.g.,

    #define FFI_LIB "/home/abc/xyz.so.0.2"
    
  3. Always use apachectl stop followed by start for updates.
    e.g.,

    $ sudo apachectl stop && sudo apachectl start
    

Approach #3 works without issues, but completely stopping and starting the master process is burdensome in a live server on-premises environment.

It would be great if there's a general method that can be used with apachectl graceful.
Below is a simplified version of my php.ini and ffi.preload header file for testing:

zend_extension=opcache
extension=ffi
ffi.enable=preload
ffi.preload=/home/abc/preload.h
opcache.enable=1
opcache.preload_user=nobody
opcache.preload=/home/abc/preload.php
#define FFI_SCOPE "XYZ"
#define FFI_LIB "/home/abc/xyz.so"
#include <stdint.h>
void xyz_hello_world(void);
int32_t xyz_this_year(void);
size_t xyz_multiply(int32_t v);

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

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

調査の方向性

php.ini と preload.h に示されている ffi.preload および opcache の設定から始め、apachectl graceful がロード済みの共有ライブラリにどのような影響を与えるかを追跡し、説明されている pmap の出力を調べます。更新を繰り返すと古い mappings が残るかどうか、また graceful reload がサポートされているかどうかを判断し、確認された動作と安全な更新手順を文書化します。

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

評価

技術スタック
apache, c, php
領域
backend, operating-systems
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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