You are here

function _acquia_purge_queue_processpurge in Acquia Purge 6

Same name and namespace in other branches
  1. 7 acquia_purge.deprecated.inc \_acquia_purge_queue_processpurge()

Queue manager: process a single path (on all domains and balancers).

@returns Boolean TRUE/FALSE indicating success or failure of the attempt.

Parameters

string $path: The Drupal path (e.g. '<front>', 'user/1' or an aliased path).

2 string references to '_acquia_purge_queue_processpurge'
acquia_purge_ajax_processor in ./acquia_purge.admin.inc
Menu callback; process a chunk of purge items via AJAX.
drush_acquia_purge_ap_process in ./acquia_purge.drush.inc
Purge all queued items from the command line.

File

./acquia_purge.module, line 766
Acquia Purge, Top-notch Varnish purging on Acquia Cloud!

Code

function _acquia_purge_queue_processpurge($path) {
  $base_path = base_path();

  // Ask our built-in diagnostics system to preliminary find issues that are so
  // risky we can expect problems. Everything with ACQUIA_PURGE_SEVLEVEL_ERROR
  // will cause purging to cease and log messages to be written. Because we
  // return FALSE, the queued items will be purged later in better weather.
  if (count($err = _acquia_purge_get_diagnosis(ACQUIA_PURGE_SEVLEVEL_ERROR))) {
    _acquia_purge_get_diagnosis_logged($err);
    return FALSE;
  }

  // Rewrite '<front>' to a empty string, which will be the frontpage. By using
  // substr() and str_replace() we still allow cases like '<front>?param=1'.
  if (drupal_substr($path, 0, 7) === '<front>') {
    $path = str_replace('<front>', '', $path);
  }

  // Because a single path can exist on http://, https://, on various domain
  // names and could be cached on any of the known load balancers. Therefore we
  // define a list of HTTP requests that we are going to fire in a moment.
  $requests = array();
  foreach (_acquia_purge_get_balancers() as $balancer_ip) {
    foreach (_acquia_purge_get_domains() as $domain) {
      foreach (_acquia_purge_get_protocol_schemes() as $scheme) {
        $rqst = new stdClass();
        $rqst->scheme = $scheme;
        $rqst->rtype = 'PURGE';
        $rqst->balancer = $balancer_ip;
        $rqst->domain = $domain;
        $rqst->path = str_replace('//', '/', $base_path . $path);
        $rqst->uri = $rqst->scheme . '://' . $rqst->domain . $rqst->path;
        $rqst->uribal = $rqst->scheme . '://' . $rqst->balancer . $rqst->path;
        $rqst->headers = array(
          'Host: ' . $rqst->domain,
          'Accept-Encoding: gzip',
          'X-Acquia-Purge: ' . _acquia_purge_get_site_name(),
        );
        $requests[] = $rqst;
      }
    }
  }

  // Before we issue these purges against the load balancers we ensure that any
  // of these URLs are not left cached in Drupal's ordinary page cache.
  $already_cleared = array();
  foreach ($requests as $rqst) {
    if (!in_array($rqst->uri, $already_cleared)) {
      cache_clear_all($rqst->uri, 'cache_page');
      $already_cleared[] = $rqst->uri;
    }
  }

  // Execute the prepared requests efficiently and log their results.
  $overall_success = TRUE;
  foreach (_acquia_purge_queue_processpurge_requests($requests) as $rqst) {
    if ($rqst->result == TRUE) {
      watchdog('acquia_purge', "Purged '%url' from load balancer %balancer.", array(
        '%url' => $rqst->uri,
        '%balancer' => $rqst->balancer,
      ), WATCHDOG_INFO);
      _acquia_purge_queue_stats($rqst->uri);
    }
    else {
      if ($overall_success) {
        $overall_success = FALSE;
      }

      // Log the failing attempt and include verbose debugging information.
      watchdog('acquia_purge', "Failed attempt to purge '%url' from load balancer %balancer for " . "unknown reasons as curl failed. The path item is re-queued! " . "Debugging symbols: '%debug',", array(
        '%url' => $rqst->uri,
        '%balancer' => $rqst->balancer,
        '%debug' => $rqst->error_debug,
      ), WATCHDOG_ERROR);
    }
  }

  // If one the many HTTP requests failed we treat the full path as a failure,
  // by sending back FALSE the item will remain in the queue. Failsafe style.
  return $overall_success;
}