How to properly restart Apache(mod-php) when updating FFI_LIB libraries in ffi.preload
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 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?
-
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 -
Always change the FFI_LIB path in the ffi.preload header file.
e.g.,#define FFI_LIB "/home/abc/xyz.so.0.2" -
Always use
apachectl stopfollowed bystartfor 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);
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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