Loading...


Related Products


Date Published: February 6, 2025

Acquia Purge domain detection

Issue

Acquia Purge isn't purging the correct domains.

Note: this article is relevant to D7 sites only. D8 and beyond does not require purge domains to be manually defined, due to the cache tag system.

Resolution

Whenever the Acquia Purge module tries to refresh pages (for example, news or ) on your site, it has to reconstruct URLs and determine which domains associated with your site should be cleaned. For most simple Drupal sites running on Acquia Cloud, this is adequate and it will just purge your primary domain name.

As the list of automatically detected domains grows larger, it is often necessary to tell Acquia Purge what domains it should clear. This often happens with multisite setups or single sites with many aliased domain names. To prevent downtimes or safety shutdowns, you should aim to purge no more than one to four domains. The module will self-shutdown whenever it detects more than eight domains.

Detecting domains and performing tests

Acquia Purge does a good job in detecting 80% of the right domains and performs a series of checks and tests. To better understand what data it uses to determine the domains, it helps to know what the module checks:

  1. Take all of the hardcoded domains in $conf['acquia_purge_domains'] and stop finding domains. If this is not overridden, automatic detection starts.
  2. Take the current HTTP_HOST the user is using to visit the site.
  3. Interpret the domain name found in $base_url when it is different.
  4. Interpret any domains (without path) found in sites/sites.php. With the introduction of the opt-in acquia_purge_sphpskippath setting, there is now experimental support for detecting domain names from sites.php records with a path in it.
  5. Add all domains on the Cloud > Domains page of the Acquia Cloud subscription.

Listing the domains

You can easily list the domains that will be purged using drush ap-domains or its alias, drush apdo from a command line. If you do not hardcode domains in settings.php or in sites.php, the detection will use environmental parameters. Using the --uri parameter with Drush simulates real-world usage:

drush ap-domains --uri="http://www.site.com"

which results in:

www.site.com

 

Overriding or hardcoding domains

If automatic detection does not find the domains correctly, or if you need to manually edit what domains it is working with, you can add this code to settings.php to change or limit the domains using code like this:

/**
 * Override domain detection in Acquia Purge.
 */
if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
  if ($_ENV['AH_SITE_ENVIRONMENT'] == 'prod') {
    $conf['acquia_purge_domains'] = array(
      'www.mysite.com',
      'www.mysite.nl',
      'www.mysite.de',
    );
  }
}

If you are an Acquia Remote Administration service customer, the code is a bit more complex.

Please note, the following case applies only to customers with the Remote Administration service.

/**
 * Override domain detection in Acquia Purge.
 */
if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
    switch ($_ENV['AH_SITE_ENVIRONMENT']) {
        case 'prod':
            // Production environment.
            $conf['acquia_purge_domains'] = array(
                'www.domain1.com',
                'www.domain2.net',
                'www.domain3.org',
            );
            break;
        case 'test':
            // Staging environment.
            $conf['acquia_purge_domains'] = array(
                'test.domain1.com',
                'test.domain2.net',
                'test.domain3.org',
            );
            break;
        case 'dev':
            // Staging environment.
            $conf['acquia_purge_domains'] = array(
                'dev.domain1.com',
                'dev.domain2.net',
                'dev.domain3.org',
            );
            break;
        case 'ra':
            // RA environment.
            $conf['acquia_purge_domains'] = array(
                'ra.domain1.com',
                'ra.domain2.net',
                'ra.domain3.org',
            );
            break;
        default:
            // Default purge domains if no specific environment detected.
            $conf['acquia_purge_domains'] = array(
                'www.domain1.com',
                'www.domain2.net',
                'www.domain3.org',
            );
    }
}    

  // Do not purge in other environments (such as local development)
else  {
    $conf['acquia_purge_passivemode'] = TRUE;

}

 

Purging Domain Access and simple multisite sites

The Domain Access module isn't officially supported yet, although it is on the project roadmap. However, you can make it work fairly easily by taking the incoming host name in the URL and assuming that to be the correct (and only) domain to be purged. This will also work for simple multisites, but it is important to test every individual site using the drush ap-domains --uri command.

/**
 * Override domain detection in Acquia Purge: hardcode the incoming domain.
 */
if (isset($_SERVER['HTTP_HOST']) && (!empty($_SERVER['HTTP_HOST']))) {
  $conf['acquia_purge_domains'] = array($_SERVER['HTTP_HOST']);
}

 

Purging larger multisites

A multisite setup is often a shared docroot and codebase where multiple domain names connect to different databases and serve different content. Acquia Purge generally has no issues purging these sites, but the standard domain detection often can detect too many domains and may cause cross-site purging.

The module will reverse parse the sites/sites.php file. This file is the recommended way of linking directories to domain names in multisite setups. Acquia Purge uses the sites/sites.php file to determine which domains belong to which sites as it purges.

As an example, imagine you have three sites:

  • fruit.com (sites/fruit)
  • apples.fruit.com (sites/apples)
  • oranges.fruit.com (sites/oranges)

The Cloud > Domains page of your Acquia Cloud subscription lists all of these domains. If you set up sites/sites.php to make this work, it should look roughly like this:

if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
  switch ($_ENV['AH_SITE_ENVIRONMENT']) {
    case 'dev':
    $sites['dev.fruit.com'] = 'fruit';
    $sites['editorial.dev.fruit.com'] = 'fruit';
    $sites['dev.apples.fruit.com'] = 'apples';
    $sites['dev.oranges.fruit.com'] = 'oranges';
    break;

    case 'test':
    $sites['test.fruit.com'] = 'fruit';
    $sites['editorial.test.fruit.com'] = 'fruit';
    $sites['test.apples.fruit.com'] = 'apples';
    $sites['test.oranges.fruit.com'] = 'oranges';
    break;

    case 'prod':
    $sites['fruit.com'] = 'fruit';
    $sites['editorial.fruit.com'] = 'fruit';
    $sites['apples.fruit.com'] = 'apples';
    $sites['oranges.fruit.com'] = 'oranges';
    break;
  }
}

Note

Acquia Purge is discouraged with the more complex use cases that sites.php supports, like ports and or subdirectories:

$sites['8080.www.drupal.org.mysite.test'] = 'example.com';

Large numbers of domains

Some Acquia customers have had large numbers of domains across multiple subscriptions. This can cause Acquia Purge to evict more items from the Varnish cache than necessary. If you have a well structured domain list in your sites.php file, you may be able to work break up the list in a fashion that enables Acquia Purge to continue working. The following code uses the $conf['acquia_purge_domains'] variable, and can be altered to change mydrupaldev and mydrupalstg to use whatever structure your website names use.

if (file_exists('sites/sites.php')) {
  $prod = $test = $dev = array();
  $sitedir = str_replace("sites/", "", conf_path());
  include "sites/sites.php";

  if (isset($sites) && is_array($sites)) {
    foreach ($sites as $site => $directory) {
      if ($directory != $sitedir) {
        continue;
      }
      if (strpos($site, "mydrupaldev")) {
        $dev[] = $site;
      }
      elseif (strpos($site, "mydrupalstg")) {
        $test = $site;
      }
      else {
        $prod[] = $site;
      }
    }
    if (isset($_ENV['AH_SITE_ENVIRONMENT'])) {
      switch ($_ENV['AH_SITE_ENVIRONMENT']) {
        case 'prod':
          $conf['acquia_purge_domains'] = $prod;
          break;

        case 'test':
          $conf['acquia_purge_domains'] = $test;
          break;

        case 'dev':
          $conf['acquia_purge_domains'] = $dev;
          break;
      }
    }
  }
}

You can use a list like this to help break up your domains - notice that there is a defined naming structure to help ensure minimal conflicts:

#transportation
$sites['transportation.myschool.edu'] = 'transportation';
$sites['transportation.mysite.myschool.edu'] = 'transportation';
$sites['transportation.mysitedev.myschool.edu'] = 'transportation';
$sites['transportation.mysitestg.myschool.edu'] = 'transportation';

#documentation
$sites['documentation.myschool.edu'] = 'documentation';
$sites['documentation.mysite.myschool.edu'] = 'documentation';
$sites['documentation.mysitedev.myschool.edu'] = 'documentation';
$sites['documentation.mysitestg.myschool.edu'] = 'documentation';

Module questions and comments

If you have any questions or comments about the module for its maintainer, or you've found a bug or some other issue, you can file an issue in the Acquia Purge issue queue .

Did not find what you were looking for?

If this content did not answer your questions, try searching or contacting our support team for further assistance.

Back to Section navigation
Back to Site navigation