大网数据广告活动
服务器运维问答

Override php-fpm pool config values with another file

· 52CE 我爱测

Having to customize the php-fpm pool configuration of a new server, I wonder if it is possible / allowed / recommended to have a new pool file, which name goes alphabetically after the original one, which only has values that ove…

问题原文

原帖链接 · Déjà vu · CC BY-SA 3.0

Having to customize the php-fpm pool configuration of a new server, I wonder if it is possible / allowed / recommended to have a new pool file, which name goes alphabetically after the original one, which only has values that override the initial configuration.

The original configuration is in /etc/php/7.0/fpm/pool.d named www.conf.

It seems, according to the pages related to the installation, engineers modify directly the original (saving a copy of the initial values). E.g.

[www]
...
user www-data
group www-data
pm.max_children 2

gives after modification

[www]
...
user myapp         ; was www-data
group myapp        ; was www-data
pm.max_children 8  ; was 2

But it seems that could be a task to be repeated after the next upgrade of php-fpm (furthermore the configuration is in a 7.0 path, that's worrying).

Instead of modifying the original file, I would like to keep it unchanged, and add another one, say wwwmyapp.conf that would declare the same pool, and having only the values that have changed

in wwwmyapp.conf

[www]        ; same pool!
user myapp
group myapp
pm.max_children 8

in pool.d, list of files

www.conf
wwwmyapp.conf

since in php-fpm.conf all pool conf files are loaded, the values of wwwmyapp will be read after the ones of www ( in the same www pool ) and should override the first values.

  • It seems to work in a few tests and no error reported, but will it work all the time, and for all values?
  • Should we overwrite the config file directly instead?

Couldn't find an answer in any doc, even on php.net.

已采纳解答

原帖链接 · Déjà vu · CC BY-SA 3.0

Could not find an "official" confirmation from another source, but here is some outcome after doing some research:

Analyzing the source code of php7.0-fpm and more specifically fpm-conf.c, it appears that

  • the main configuration file php-fpm.conf is read first [ fpm_conf_load_ini_file() ],
  • all include directives are read in order, giving a list of files thanks to glob(),
  • each of the file is parsed by the same fpm_conf_load_ini_file(),
  • an entry in the file overwrites any previously set value,
  • any new include will have a recursive call to the includes processing function, and
  • the glob() function sorts names, by default (no GLOB_NOSORT option)

Thus we can assume - at least in this version but this is unlikely to change soon considering the present code - that it is safe to arrange the pool.d directory configuration files in alphabetical order ; any previously recorded value being overwritten by an entry with the same name read after.

We have a clean way to handle configuration files for php-fpm, keeping the distribution ones untouched, and adding custom files having name alphabetically greater than the packaged ones, that contain the few options that have to be changed.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-09-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。