php Acquia D8 Memcache示例配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php Acquia D8 Memcache示例配置相关的知识,希望对你有一定的参考价值。

<?php
/**
 * @file
 * Contains memcache configuration.
 */
use Composer\Autoload\ClassLoader;

/**
 * Use memcache as cache backend.
 *
 * Autoload memcache classes and service container in case module is not
 * installed. Avoids the need to patch core and allows for overriding the
 * default backend when installing Drupal.
 *
 * @see https://www.drupal.org/node/2766509
 */

if (getenv('AH_SITE_ENVIRONMENT') && 
  isset($settings['memcache']['servers'])
) {

// Check for PHP Memcached libraries.
$memcache_exists = class_exists('Memcache', FALSE);
$memcached_exists = class_exists('Memcached', FALSE);
$memcache_module_is_present = file_exists(DRUPAL_ROOT . '/modules/contrib/memcache/memcache.services.yml');
if ($memcache_module_is_present && ($memcache_exists || $memcached_exists)) {
  // Use Memcached extension if available.
  if ($memcached_exists) {
    $settings['memcache']['extension'] = 'Memcached';
  }
  if (class_exists(ClassLoader::class)) {
    $class_loader = new ClassLoader();
    $class_loader->addPsr4('Drupal\\memcache\\', 'modules/contrib/memcache/src');
    $class_loader->register();
    $settings['container_yamls'][] = DRUPAL_ROOT . '/modules/contrib/memcache/memcache.services.yml';
    // Bootstrap cache.container with memcache rather than database.
    $settings['bootstrap_container_definition'] = [
      'parameters' => [],
      'services' => [
        'database' => [
          'class' => 'Drupal\Core\Database\Connection',
          'factory' => 'Drupal\Core\Database\Database::getConnection',
          'arguments' => ['default'],
        ],
        'settings' => [
          'class' => 'Drupal\Core\Site\Settings',
          'factory' => 'Drupal\Core\Site\Settings::getInstance',
        ],
        'memcache.config' => [
          'class' => 'Drupal\memcache\DrupalMemcacheConfig',
          'arguments' => ['@settings'],
        ],
        'memcache.backend.cache.factory' => [
          'class' => 'Drupal\memcache\DrupalMemcacheFactory',
          'arguments' => ['@memcache.config'],
        ],
        'memcache.backend.cache.container' => [
          'class' => 'Drupal\memcache\DrupalMemcacheFactory',
          'factory' => ['@memcache.backend.cache.factory', 'get'],
          'arguments' => ['container'],
        ],
        'lock.container' => [
          'class' => 'Drupal\memcache\Lock\MemcacheLockBackend',
          'arguments' => ['container', '@memcache.backend.cache.container'],
        ],
        'cache_tags_provider.container' => [
          'class' => 'Drupal\Core\Cache\DatabaseCacheTagsChecksum',
          'arguments' => ['@database'],
        ],
        'cache.container' => [
          'class' => 'Drupal\memcache\MemcacheBackend',
          'arguments' => [
            'container',
            '@memcache.backend.cache.container',
            '@lock.container',
            '@memcache.config',
            '@cache_tags_provider.container',
          ],
        ],
      ],
    ];
    // Override default fastchained backend for static bins.
    // @see https://www.drupal.org/node/2754947
    $settings['cache']['bins']['bootstrap'] = 'cache.backend.memcache';
    $settings['cache']['bins']['discovery'] = 'cache.backend.memcache';
    $settings['cache']['bins']['config'] = 'cache.backend.memcache';
    // Use memcache as the default bin.
    $settings['cache']['default'] = 'cache.backend.memcache';
    // Enable stampede protection.
    $settings['memcache']['stampede_protection'] = TRUE;
    // Move locks to memcache (This path may need to be modified)
    $settings['container_yamls'][] = 'memcache.yml';
    // Enable compression for PHP 7.
    $settings['memcache']['options'] = [
      Memcached::OPT_COMPRESSION => TRUE,
    ];
  }
 }
}
services:
  # Replaces the default lock backend with a memcache implementation.
  lock:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: memcache.lock.factory:get
  # Replaces the default persistent lock backend with a memcache implementation.
  lock.persistent:
    class: Drupal\Core\Lock\LockBackendInterface
    factory: memcache.lock.factory:getPersistent
/**
 * @file
 * Example implementation of ACSF post-settings-php hook.
 *
 * @see https://docs.acquia.com/site-factory/tiers/paas/workflow/hooks
 */

// The path to this file should be docroot/factory-hooks/post-settings-php/memcache.php
 
// Use ACSF internal settings site flag to apply memcache settings.
if (getenv('AH_SITE_ENVIRONMENT') && 
	isset($site_settings['flags']['memcache_enabled']) &&
	isset($settings['memcache']['servers'])
) {
  require '[path-to-project-settings]/memcacheD8.settings.php';
}

以上是关于php Acquia D8 Memcache示例配置的主要内容,如果未能解决你的问题,请参考以下文章

sh Flush Acquia memcache

Composer 读取错误的 PHP 版本(Windows 上的 ACQUIA DEV DESKTOP)

Drupal.info示例

Memcached&PHP-Memcache安装配置

PHP memcached 致命错误:找不到类“Memcache”

sh 截断Acquia SOLR核心