Skip to content

Instantly share code, notes, and snippets.

@turneliusz
Created March 1, 2017 08:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save turneliusz/f01c8bd5f3b97a82e38928f4ebc2542f to your computer and use it in GitHub Desktop.
Save turneliusz/f01c8bd5f3b97a82e38928f4ebc2542f to your computer and use it in GitHub Desktop.
Automatic setup of PHP-FPM pool max-children
#!/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