#!/usr/bin/env bash # Memcached Installer # Min. Requirement : GNU/Linux Ubuntu 14.04 & 16.04 # Last Build : 17/07/2019 # Author : ESLabs.ID (eslabs.id@gmail.com) # Since Version : 1.0.0 # Include helper functions. if [ "$(type -t run)" != "function" ]; then BASEDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd ) # shellchechk source=scripts/helper.sh # shellcheck disable=SC1090 . "${BASEDIR}/helper.sh" fi # Make sure only root can run this installer script. requires_root function enable_memcache { # PHP version. local PHPv="${1}" if [ -z "${PHPv}" ]; then PHPv=${PHP_VERSION:-"7.3"} fi if "${DRYRUN}"; then echo "Optimizing PHP Memcache module in dryrun mode." else # Custom Memcache setting. local RAM_SIZE && \ RAM_SIZE=$(get_ram_size) if [[ ${RAM_SIZE} -le 1024 ]]; then # If machine RAM less than / equal 1GiB, set Memcached to 1/8 of RAM size. local MEMCACHED_SIZE=$((RAM_SIZE / 8)) elif [[ ${RAM_SIZE} -gt 2048 && ${RAM_SIZE} -le 8192 ]]; then # If machine RAM less than / equal 8GiB and greater than 2GiB, set Memcached to 1/4 of RAM size. local MEMCACHED_SIZE=$((RAM_SIZE / 4)) else # Otherwise, set Memcached to max of 2048GiB. local MEMCACHED_SIZE=2048 fi sed -i "s/-m 64/-m ${MEMCACHED_SIZE}/g" /etc/memcached.conf if [ -d "/etc/php/${PHPv}/mods-available/" ]; then cat >> "/etc/php/${PHPv}/mods-available/memcache.ini" <