From cbc7ced3e9a2488c2b956ea98a7adefef248ccf8 Mon Sep 17 00:00:00 2001 From: George Liu Date: Wed, 24 Jan 2018 00:07:35 +1000 Subject: [PATCH] add CLOUDFLARE_ZLIBPHP variable to use Cloudflare zlib fork for PHP compiles - optional not enabled by default CLOUDFLARE_ZLIBPHP='n' when enabled and set CLOUDFLARE_ZLIBPHP='y' in persistent config file /etc/centminmod/custom_config.inc prior to PHP recompiles via centmin.sh menu option 5, will switch PHP-FPM usage of zlib from system zlib version to performance forked Cloudflare zlib library which has already been show to improve Nginx zlib compression performance by at least 22-29% https://community.centminmod.com/threads/123-09beta01-updated-nginx-zlib-routine-with-optional-cloudflare-zlib-support.13521/ --- centmin.sh | 1 + example/custom_config.inc | 1 + inc/php_configure.inc | 23 +++++++++++++++---- inc/zlib.inc | 48 +++++++++++++++++++++------------------ tools/nginxupdate.sh | 1 + 5 files changed, 48 insertions(+), 26 deletions(-) diff --git a/centmin.sh b/centmin.sh index 83e494ced..8e573375d 100755 --- a/centmin.sh +++ b/centmin.sh @@ -554,6 +554,7 @@ OPENSSL_THREADS='y' # control whether openssl 1.1 branch uses threading o OPENSSL_CUSTOMPATH='/opt/openssl' # custom directory path for OpenSSL 1.0.2+ CLOUDFLARE_PATCHSSL='n' # set 'y' to implement Cloudflare's chacha20 patch https://github.com/cloudflare/sslconfig CLOUDFLARE_ZLIB='n' # use Cloudflare optimised zlib fork https://blog.cloudflare.com/cloudflare-fights-cancer/ +CLOUDFLARE_ZLIBPHP='n' # use Cloudflare optimised zlib fork for PHP-FPM zlib instead of system zlib CLOUDFLARE_ZLIBDEBUG='n' # make install debug verbose mode CLOUDFLARE_ZLIBVER='1.3.0' NGINX_DYNAMICTLS='n' # set 'y' and recompile nginx https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency/ diff --git a/example/custom_config.inc b/example/custom_config.inc index bb5c68cb0..bd030d57b 100644 --- a/example/custom_config.inc +++ b/example/custom_config.inc @@ -234,6 +234,7 @@ OPENSSL_THREADS='y' # control whether openssl 1.1 branch uses threading o OPENSSL_CUSTOMPATH='/opt/openssl' # custom directory path for OpenSSL 1.0.2+ CLOUDFLARE_PATCHSSL='n' # set 'y' to implement Cloudflare's chacha20 patch https://github.com/cloudflare/sslconfig CLOUDFLARE_ZLIB='n' # use Cloudflare optimised zlib fork https://blog.cloudflare.com/cloudflare-fights-cancer/ +CLOUDFLARE_ZLIBPHP='n' # use Cloudflare optimised zlib fork for PHP-FPM zlib instead of system zlib CLOUDFLARE_ZLIBDEBUG='n' # make install debug verbose mode CLOUDFLARE_ZLIBVER='1.3.0' NGINX_DYNAMICTLS='n' # set 'y' and recompile nginx https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency/ diff --git a/inc/php_configure.inc b/inc/php_configure.inc index 5c77e8680..b11649529 100644 --- a/inc/php_configure.inc +++ b/inc/php_configure.inc @@ -22,6 +22,21 @@ CHECKLOWMEMPHP=`expr $TOTALMEM \< $ISLOWMEMPHP` PLIBDIR='/usr' PHPMVER=$(echo "$PHP_VERSION" | cut -d . -f1,2) +# whether to switch from system used zlib to cloudflare zlib performance +# fork for php conmpilations for cpus supporting SSE4.2 at least +if [[ "$CLOUDFLARE_ZLIBPHP" = [yY] && "$(cat /proc/cpuinfo | grep -o 'sse4_2' | uniq)" = 'sse4_2' ]]; then + # check if static libz.a installed usually as result of compiling nginx with + # CLOUDFLARE_ZLIB='y' set but if not installed run install function from inc/zlib.inc + if [ ! -f /usr/local/zlib-cf/lib/libz.a ]; then + install_cfzlib + ZLIBPHP_OPT='--with-zlib-dir=/usr/local/zlib-cf' + elif [ -f /usr/local/zlib-cf/lib/libz.a ]; then + ZLIBPHP_OPT='--with-zlib-dir=/usr/local/zlib-cf' + fi +else + ZLIBPHP_OPT='--with-zlib' +fi + # php modules to disable for low memory installs if # LOWMEM_INSTALL='y' is set # https://community.centminmod.com/posts/46321/ @@ -714,15 +729,15 @@ fi if [[ "$MDB_INSTALL" == [yY] || "$MYSQL_INSTALL" == [yY] ]]; then - echo "../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS}" + echo "../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash ${ZLIBPHP_OPT} --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS}" -../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS} +../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash ${ZLIBPHP_OPT} --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS} else - echo "../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS}" + echo "../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash ${ZLIBPHP_OPT} --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS}" -../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash --with-zlib --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS} +../configure --enable-fpm${OPCACHEOPT}${PHPINTLOPT}${PCNTLOPT}${MCRYPT}${RECODEOPT}${SNMPOPT}${PHPEMBEDOPT} --with-mhash ${ZLIBPHP_OPT} --with-gettext --enable-exif --enable-zip${LIBZIP_OPT} --with-bz2 --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --with-pear --enable-mbstring $PHP_OPENSSLOPT --with-mysql=mysqlnd --with-libdir=${LIBDIR} --with-mysqli=mysqlnd --with-mysql-sock=${PHP_MYSQLSOCKPATH}/mysql.sock --with-curl --with-gd --with-xmlrpc --enable-bcmath --enable-calendar${FTPEXTOPT} --enable-gd-native-ttf --with-freetype-dir=${PLIBDIR} --with-jpeg-dir=${PLIBDIR} --with-png-dir=${PLIBDIR} --with-xpm-dir=${PLIBDIR}${LIBVPXOPT}${TLIBOPT} --enable-pdo${PDOSQLLITE_OPT} --with-pdo-mysql=mysqlnd${MSSQLOPT} --enable-inline-optimization${IMAPOPT} --with-kerberos --with-readline --with-libedit --with-gmp --with-pspell --with-tidy --with-enchant --with-fpm-user=nginx --with-fpm-group=nginx${FILEINFOOPT}${SQLLITEOPT}${LDAPOPT}${PDOPGSQL_OPT}${OPCACHEHUGEPAGES_OPT}${ARGONTWO_OPT}${LIBSODIUM_OPT} --with-config-file-scan-dir=${CONFIGSCANDIR}${PHPDEBUGOPT}${PHP_EXTRAOPTS} fi sar_call diff --git a/inc/zlib.inc b/inc/zlib.inc index 81da2207a..bdc2ae81b 100644 --- a/inc/zlib.inc +++ b/inc/zlib.inc @@ -63,21 +63,7 @@ zlibng_install() { fi } -nginxzlib_install() { - if [[ "$NGINX_ZLIBCUSTOM" = [yY] ]]; then - if [[ "$CLOUDFLARE_ZLIB" = [yY] && "$(cat /proc/cpuinfo | grep -o 'sse4_2' | uniq)" = 'sse4_2' ]]; then - # disable clang compiler and switch to gcc compiler due to clang 3.4.2 errors when enabling - # cloudflare zlib - if [[ "$CLANG" = [yY] && "$CENTOS_SEVEN" -eq '7' ]]; then - CLANG='y' - CLANG_FOUR='y' - elif [[ "$CLANG" = [yY] && "$CENTOS_SIX" -eq '6' ]]; then - CLANG='n' - DEVTOOLSETSIX='y' - else - CLANG='n' - DEVTOOLSETSIX='y' - fi +install_cfzlib() { echo echo "install zlib cloudflare..." echo @@ -95,15 +81,33 @@ nginxzlib_install() { # ldconfig make -f Makefile.in distclean popd - # # ./configure --prefix=/usr/local/zlib-cf + ./configure --prefix=/usr/local/zlib-cf --static # ./configure - # make${MAKETHREADS} + make${MAKETHREADS} # ps aufxwww > zlib-process.log - # if [[ "$CLOUDFLARE_ZLIBDEBUG" = [Yy] ]]; then - # make -d install - # else - # make install - # fi + if [[ "$CLOUDFLARE_ZLIBDEBUG" = [Yy] ]]; then + make -d install + else + make install + fi +} + +nginxzlib_install() { + if [[ "$NGINX_ZLIBCUSTOM" = [yY] ]]; then + if [[ "$CLOUDFLARE_ZLIB" = [yY] && "$(cat /proc/cpuinfo | grep -o 'sse4_2' | uniq)" = 'sse4_2' ]]; then + # disable clang compiler and switch to gcc compiler due to clang 3.4.2 errors when enabling + # cloudflare zlib + if [[ "$CLANG" = [yY] && "$CENTOS_SEVEN" -eq '7' ]]; then + CLANG='y' + CLANG_FOUR='y' + elif [[ "$CLANG" = [yY] && "$CENTOS_SIX" -eq '6' ]]; then + CLANG='n' + DEVTOOLSETSIX='y' + else + CLANG='n' + DEVTOOLSETSIX='y' + fi + install_cfzlib if [ -f /usr/local/lib/libz.so ]; then echo ps aufxw diff --git a/tools/nginxupdate.sh b/tools/nginxupdate.sh index cd792f452..7cc6771fd 100755 --- a/tools/nginxupdate.sh +++ b/tools/nginxupdate.sh @@ -332,6 +332,7 @@ OPENSSL_VERSIONFALLBACK='1.0.2n' # fallback if OPENSSL_VERSION uses openssl 1. OPENSSL_THREADS='y' # control whether openssl 1.1 branch uses threading or not CLOUDFLARE_PATCHSSL='n' # set 'y' to implement Cloudflare's chacha20 patch https://github.com/cloudflare/sslconfig CLOUDFLARE_ZLIB='n' # use Cloudflare optimised zlib fork https://blog.cloudflare.com/cloudflare-fights-cancer/ +CLOUDFLARE_ZLIBPHP='n' # use Cloudflare optimised zlib fork for PHP-FPM zlib instead of system zlib CLOUDFLARE_ZLIBDEBUG='n' # make install debug verbose mode CLOUDFLARE_ZLIBVER='1.3.0' NGINX_DYNAMICTLS='n' # set 'y' and recompile nginx https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency/