Let the platform do the work

Improving On-Site Performance With PHP Caching

Overview

When running Sugar on-site, it is important to optimize your server to get the best performance possible. In this article we will show you a couple of performance-optimizing options, primarily PHP caching. PHP caching is used in combination with PHP and the web server to build and store dynamic information. This allows for PHP to operate more efficiently. For more information, please refer to the PHP Caching documentation in the Performance pages of the Developer Guide specific to your Sugar version.

Among various PHP caching options, OPcache is strongly recommended. OPcache compiles human-readable PHP code into opcode—the machine-understandable format—which improves performance significantly. For more information about recommended stack components, please refer to the Supported Platforms page.

Prerequisites

  • You have an on-site instance.
  • You have admin access to the server hosting your on-site Sugar instance.
  • You have experience administrating your web server and installing and configuring stack components.

Steps to Complete

Enabling OPCache

OPCcache has been enabled for the most recent PHP installs, if not, OPcache must be compiled as a shared extension. If default extensions were disabled during the PHP build process (e.g., using --disable-all), OPcache must be explicitly enabled using the --enable-opcache configuration option when compiling PHP.

Once compiled, load the OPcache extension by adding the appropriate zend_extension directive to the php.ini file:

  • Linux/MacOS
  zend_extension=/full/path/to/opcache.so

  • Windows
  zend_extension=C:\path\to\php_opcache.dll

Refer to the official PHP manual for platform-specific instructions and further details.

The following configuration values are recommended as a baseline for improved performance. Tweak these settings as needed to suit specific requirements of your infrastructure:

  opcache.enable=1
opcache.memory_consumption=256
opcache.interned_strings_buffer=16
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.validate_timestamps=1
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.blacklist_filename=/full/path/to/opcache_blacklist.txt

Note: The opcache.blacklist_filename directive points to a text file that contains a list of files to be excluded from caching. This is useful for excluding dynamically generated or frequently modified files from acceleration. Each file path should be listed on a separate line.

  ; SugarCRM dynamic cache files
/full/path/to/sugar_instance/cache/class_map.php
/full/path/to/sugar_instance/cache/api/metadata/hashes.php
/full/path/to/sugar_instance/cache/modules/Teams/TeamsSetCache.php
/full/path/to/sugar_instance/cache/smarty/templates_c/*
/full/path/to/sugar_instance/config_override.php
/full/path/to/sugar_instance/config.php
/full/path/to/sugar_instance/custom/include/config.php
/full/path/to/sugar_instance/custom/modules/unified_search_modules_display.php

External Cache

External caching is essential for achieving optimal performance. It significantly reduces file system reads and SQL query executions, among other benefits. Redis is the recommended solution.

Installing Redis

If your instance is running on Linux or Windows, you will want to use Redis. For more information on installing Redis on your server, refer to the Install Redis page on the Redis website. Please note that PHP may be missing the Redis extension out of the box, but it can be installed using the instructions on this PHP page.

Once Redis is installed, be sure to configure the following config options in Sugar:

  $sugar_config['external_cache_disabled'] = false; 

$sugar_config['external_cache_disabled_redis'] = false; 

$sugar_config['external_cache']['redis']['host'] = 127.0.0.1; // address of the redis server 

$sugar_config['external_cache']['redis']['port'] = 6379; // Only required if port different than the default 6379

Disabling External Cache

In server configurations where you have multiple external caches enabled for other applications and services, you may want to ensure only specific external caching is configured for your Sugar instance. To disable one or more external caches, you can edit the ./config_override.php file and enter any combination of the following lines of code:

  $sugar_config['external_cache_disabled'] = true; // Disables all external caching

$sugar_config['external_cache_disabled_memcache'] = true; // Disables Memcache

$sugar_config['external_cache_disabled_memcached'] = true; // Disables Memcached

$sugar_config['external_cache_disabled_redis'] = true; // Disables Redis

$sugar_config['external_cache_disabled_smash'] = true; // Disables sMash

$sugar_config['external_cache_disabled_wincache'] = true; // Disables Wincache

$sugar_config['external_cache_disabled_zend'] = true; // Disables Zend

Note: If you are installing Redis, or another cache specifically to improve Sugar performance, you should not include the corresponding configuration line from above in your ./config_override.php. Doing so would prevent your Sugar instance from utilizing the desired caching service.

Other Performance Tips

A final tip is to always make sure that your server has adequate memory and processor processing power to run the operating system, web server (Apache or IIS), Database, and Sugar's PHP pages. As the Sugar administrator, you can usually check your running services to determine the overall load on the server. From there, you should be able to determine the appropriate actions to take, whether it be upgrading the server hardware, software, etc.

Note: If you are running an on-site instance, we have an XHProf tool that can help profile the performance of PHP pages within your instance in more detail. For more information please, reference the PHP Profiling documentation in the Application Framework and Performance pages of the Developer Guide specific to your version of Sugar.