Skip to content

Instantly share code, notes, and snippets.

@mikebronner
Created February 25, 2019 22:38
Show Gist options
  • Save mikebronner/77eead0a9214b938df14ae8ebd40a69e to your computer and use it in GitHub Desktop.
Save mikebronner/77eead0a9214b938df14ae8ebd40a69e to your computer and use it in GitHub Desktop.
Fix PHP process_control_timeout and max_execution_time settings.
#!/bin/bash
set -e
MET_PATTERN='[[:space:]]*max_execution_time[[:space:]]*=[[:space:]]*'
PCT_PATTERN='[[:space:]]*process_control_timeout[[:space:]]*=[[:space:]]*'
VALUE=30
reload=0
# replace setting in php.ini file: max_execution_time
for file in /etc/php/*/fpm/php.ini
do
if grep -Eq "^$MET_PATTERN$VALUE[[:space:]]*(;.*)?$" "$file"
then
# case 0: is already set correctly -> do nothing
echo -n '= no change '
elif grep -Eq "^$MET_PATTERN" "$file"
then
# case 1: is defined -> modify
echo -n '~ line modified '
sed -ri "s/^($MET_PATTERN).*$/\1$VALUE/" "$file"
reload=1
elif grep -Eq "^[[:space:]]*;$MET_PATTERN" "$file"
then
# case 2: is commented out -> insert below
echo -n '+ line inserted below '
sed -ri "/^[[:space:]]*;$MET_PATTERN/a max_execution_time = $VALUE" "$file"
reload=1
else
# case 3: does not exist -> insert at top of [PHP] section
echo -n '^ line inserted at top'
sed -ri "/^\[PHP\]/Ia max_execution_time = $VALUE/" "$file"
reload=1
fi
echo " - $file"
done
# replace setting in php-fpm.conf: process_control_timeout
for file in /etc/php/*/fpm/php-fpm.conf
do
if grep -Eq "^$PCT_PATTERN$VALUE[[:space:]]*(;.*)?$" "$file"
then
# case 0: is already set correctly -> do nothing
echo -n '= no change '
elif grep -Eq "^$PCT_PATTERN" "$file"
then
# case 1: is defined -> modify
echo -n '~ line modified '
sed -ri "s/^($PCT_PATTERN).*$/\1$VALUE/" "$file"
reload=1
elif grep -Eq "^[[:space:]]*;$PCT_PATTERN" "$file"
then
# case 2: is commented out -> insert below
echo -n '+ line inserted below '
sed -ri "/^[[:space:]]*;$PCT_PATTERN/a process_control_timeout = $VALUE" "$file"
reload=1
else
# case 3: does not exist -> insert at top of [PHP] section
echo -n '^ line inserted at top'
sed -ri "/^\[global\]/Ia process_control_timeout = $VALUE/" "$file"
reload=1
fi
echo " - $file"
done
if [ $reload -gt 0 ]
then
php_version=`php -r 'echo phpversion();' | grep -Eo '^[[:digit:]]+\.[[:digit:]]+'`
service="php$php_version-fpm"
echo -n "Reloading $service ... "
service "$service" reload
echo done.
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment