Created
March 1, 2017 08:43
-
-
Save turneliusz/f01c8bd5f3b97a82e38928f4ebc2542f to your computer and use it in GitHub Desktop.
Automatic setup of PHP-FPM pool max-children
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -e | |
FPM_PROCESS_MEMORY_MB=60 | |
RESERVE_INSTANCE_MEMORY=100 | |
FPM_POOL_FILE=/etc/php/7.0/fpm/pool.d/www.conf | |
MEM_KB=`grep MemTotal /proc/meminfo | awk '{print $2}'` | |
MEM_FOR_FPM_MB=$(($MEM_KB/1024-$RESERVE_INSTANCE_MEMORY)) | |
FPM_PROCESSES=$(($MEM_FOR_FPM_MB/$FPM_PROCESS_MEMORY_MB)) | |
echo "Calculated amount of PHP-FPM processes (from $MEM_FOR_FPM_MB MB): $FPM_PROCESSES" | |
FPM_PROCESSES=${FPM_PROCESSES%.*} | |
sed -i -e "s/;*pm.max_children\s*=.*/pm.max_children = $FPM_PROCESSES/g" $FPM_POOL_FILE | |
echo "Amount of PHP-FPM processes set to $FPM_PROCESSES" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment