B
bertin.louis7
September 29, 2025
Variables Custom et multi-env dans PHP-FPM avec un PaaS
Article
Français
Le problĂšme
Adapter pm.max_spare, pm.start_servers sans dupliquer les configs.
Ici j'utilise Scalingo, mais c'est la mĂȘme idĂ©e pour d'autres PaaS
La solution
Ici j'utilise Scalingo, mais c'est la mĂȘme idĂ©e pour d'autres PaaS
La solution
- - Template avec placeholders
; .scalingo/config/php-fpm/php-fpm-custom.conf pm.max_spare = PM_MAX_CHILDREN_PLACEHOLDER pm.start_servers = PM_START_SERVERS_PLACEHOLDER
- - Config Composer
{ "extra": { "paas": { "php-fpm-includes": [".scalingo/config/php-fpm/php-fpm-custom.conf"] } }, "scripts": { "compile": ["php build.php"] } }
- - Script de remplacement
- ; build.php
<?php
$appName = getenv('APP') ?: 'default'; $targetFile = '/app/vendor/php/etc/fpm.d/php-fpm-custom.conf';$phpFpmConfigs = [ 'default' => [ 'start_servers' => 3, 'min_spare' => 3, 'max_spare' => 7 ] ]; $config = $phpFpmConfigs[$appName] ?? $phpFpmConfigs['default']; shell_exec("sed -i 's|PM_START_SERVERS_PLACEHOLDER|{$config['start_servers']}|g' $targetFile"); shell_exec("sed -i 's|PM_MIN_SPARE_PLACEHOLDER|{$config['min_spare']}|g' $targetFile"); shell_exec("sed -i 's|PM_MAX_SPARE_PLACEHOLDER|{$config['max_spare']}|g' $targetFile");
B
bertin.louis7
Auteur de cet article