I have Domain Access and Boost on my site. I'm trying to get Boost to clear its caches on each cron run. This is what I've done so far:

1. Set up a cron call on the hosting provider's interface:

wget -O - -q -t 1 http://domain.com/cron.php?cron_key=mykey

2. Set up separate cron calls, one for each domain:

wget -O - -q -t 1 http://domain.com/cron.php?cron_key=mykey 

wget -O - -q -t 1 http://subdomain1.domain.com/cron.php?cron_key=mykey 

wget -O - -q -t 1 http://subdomain2.domain.com/cron.php?cron_key=mykey 

Finally, implemented hook_domaincron() in a custom module:

<?php
/**
 * Implements hook_domaincron().
 */
function mymodule_domaincron($domain) {
  $url = 'http://' . $domain['subdomain'] . '/cron.php?cron_key=mykey';
  $response = drupal_http_request($url);
  watchdog('mymodule cron monitor', 'url: ' . $domain['subdomain'] . ', response: ' . $response->code);
}
?>

I see the cron calls in the Drupal log, but only the first domain cache is ever cleared. Similarly, when I go to domain.com/admin/reports/status, subdomain1.com/admin/reports/status, subdomain2.com/admin/reports/status and run cron from the browser, the cache is flushed, but only for the actual domain. If I call cron from outside in a browser, same result.

I'm not sure if it's a Boost or Domain Access issue. But Boost seems to be doing its job, and the problem is that no matter which way I call cron programmatically, the sub/domain information is lost. It only works when requesting cron in the browser. Any hint or advice is appreciated.

Comments

Anonymous’s picture

I think the problem is that (1) Boost is only flushing the current domain's cache, and (2) Domain Access is firing cron calls for each sub/domain while the previous domain's job has not yet finished. The Drupal log is full of "Attempting to run cron while it's already running" messages, one for each sub/domain.

agentrickard’s picture

Category: bug » support

Not a bug. The wget setup that you have actually will run the same cron script each time, which is why it's erroring out.

Looking at your code, you are using hook_domaincron incorrectly. It is not designed to let you run cron multiple times. It is designed to run one block of code across each domain. That is, instead of trying to run cron for the $domain, you should instead act on the $domain variable. Look at the code inside domain_cron() to see what is actually happening.

Here's what the API docs say, explicitly:

 * Each module implementing this hook will have the function run
 * once per active domain record.  The global $_domain variable
 * will be set to the current $domain passed as an argument.

I don't know how Boost handles its cache, so I can't tell you more than that. Normal Drupal page cache uses a distinct cache id that maps to the absolute URL.

agentrickard’s picture

You can also try the provided setting 'Treat cron.php as a special page request.' to disable DA on cron runs.

agentrickard’s picture

The following code might Just Work(tm):

function custom_domaincron($domain) {
  boost_cron();
}

If that fails, then you'll need to try resetting the global variable $base_root based on domain first.

function custom_domaincron($domain) {
  global $base_root;
  if (isset($domain['path'])) {
    $base_root = $domain['path'];
  }
  boost_cron();
}

Or some variant of the above.

Looking at the boost code, where are your domain-specific cache files getting written? One directory? Multiple directories?

Anonymous’s picture

Status: Active » Closed (fixed)

Many thanks. For copypasters: the hook name is hook_domain_cron, with an underscore:

<?php
/*
 * Implements hook_domain_cron().
 */
function MODULENAME_domain_cron($domain) {
  global $base_root;
  if (isset($domain['path'])) {
    $base_root = $domain['path'];
  }
  boost_cron();
}
?>
arun ak’s picture

I am facing same issue and added this hook mentioned in comment #5. But getting this error
ArgumentCountError: Too few arguments to function mymodule_domain_cron(), 0 passed in /var/www/ak/mywebsite/web/includes/module.inc on line 934 and exactly 1 expected in mymodule_domain_cron() (Zeile 941 von /var/www/ak/mywebsite/web/sites/all/modules/mymodule.module).