xcache.sh 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/bin/bash
  2. # Author: yeho <lj2007331 AT gmail.com>
  3. # BLOG: https://linuxeye.com
  4. #
  5. # Notes: OneinStack for CentOS/RedHat 7+ Debian 9+ and Ubuntu 16+
  6. #
  7. # Project home page:
  8. # https://oneinstack.com
  9. # https://github.com/oneinstack/oneinstack
  10. Install_XCache() {
  11. if [ -e "${php_install_dir}/bin/phpize" ]; then
  12. pushd ${oneinstack_dir}/src > /dev/null
  13. phpExtensionDir=$(${php_install_dir}/bin/php-config --extension-dir)
  14. PHP_detail_ver=$(${php_install_dir}/bin/php-config --version)
  15. PHP_main_ver=${PHP_detail_ver%.*}
  16. if [[ "${PHP_main_ver}" =~ ^5.[3-6]$ ]]; then
  17. tar xzf xcache-${xcache_ver}.tar.gz
  18. pushd xcache-${xcache_ver} > /dev/null
  19. ${php_install_dir}/bin/phpize
  20. ./configure --enable-xcache --enable-xcache-coverager --enable-xcache-optimizer --with-php-config=${php_install_dir}/bin/php-config
  21. make -j ${THREAD} && make install
  22. if [ -f "${phpExtensionDir}/xcache.so" ]; then
  23. /bin/cp -R htdocs ${wwwroot_dir}/default/xcache
  24. popd > /dev/null
  25. chown -R ${run_user}:${run_group} ${wwwroot_dir}/default/xcache
  26. touch /tmp/xcache;chown ${run_user}:${run_group} /tmp/xcache
  27. let xcacheCount="${CPU}+1"
  28. let xcacheSize="${Memory_limit}/2"
  29. cat > ${php_install_dir}/etc/php.d/04-xcache.ini << EOF
  30. [xcache-common]
  31. extension=xcache.so
  32. [xcache.admin]
  33. xcache.admin.enable_auth=On
  34. xcache.admin.user=admin
  35. xcache.admin.pass="${xcachepwd_md5}"
  36. [xcache]
  37. xcache.size=${xcacheSize}M
  38. xcache.count=${xcacheCount}
  39. xcache.slots=8K
  40. xcache.ttl=3600
  41. xcache.gc_interval=300
  42. xcache.var_size=4M
  43. xcache.var_count=${xcacheCount}
  44. xcache.var_slots=8K
  45. xcache.var_ttl=0
  46. xcache.var_maxttl=0
  47. xcache.var_gc_interval=300
  48. xcache.test=Off
  49. xcache.readonly_protection=Off
  50. xcache.shm_scheme=mmap
  51. xcache.mmap_path=/tmp/xcache
  52. xcache.coredump_directory=
  53. xcache.cacher=On
  54. xcache.stat=On
  55. xcache.optimizer=Off
  56. [xcache.coverager]
  57. ; enabling this feature will impact performance
  58. ; enable only if xcache.coverager == On && xcache.coveragedump_directory == "non-empty-value"
  59. ; enable coverage data collecting and xcache_coverager_start/stop/get/clean() functions
  60. xcache.coverager = Off
  61. xcache.coverager_autostart = On
  62. xcache.coveragedump_directory = ""
  63. EOF
  64. echo "${CSUCCESS}PHP xcache module installed successfully! ${CEND}"
  65. rm -rf xcache-${xcache_ver}
  66. else
  67. echo "${CFAILURE}PHP xcache module install failed, Please contact the author! ${CEND}" && grep -Ew 'NAME|ID|ID_LIKE|VERSION_ID|PRETTY_NAME' /etc/os-release
  68. fi
  69. else
  70. echo; echo "${CWARNING}Your php ${PHP_detail_ver} does not support XCache! ${CEND}";
  71. fi
  72. popd > /dev/null
  73. fi
  74. }
  75. Uninstall_XCache() {
  76. if [ -e "${php_install_dir}/etc/php.d/04-xcache.ini" ]; then
  77. rm -rf ${php_install_dir}/etc/php.d/04-xcache.ini ${wwwroot_dir}/default/xcache /tmp/xcache
  78. echo; echo "${CMSG}PHP xcache module uninstall completed${CEND}"
  79. else
  80. echo; echo "${CWARNING}PHP xcache module does not exist! ${CEND}"
  81. fi
  82. }