Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Since Drupal 7 has now cron_key
, we can't use wget method to call the cron.php without cron_key
with the help of hosting_cron_use_backend
variable.
I tried to fix this, so it will force backend method for any known D7 profile, even when hosting_cron_use_backend
is set to false, by something like:
function hosting_cron_queue($count) {
$sites = hosting_cron_get_sites($count);
foreach ($sites as $site) {
$site_name = hosting_context_name($site->nid);
$profile = some_magic_fetch($site->profile);
if (variable_get('hosting_cron_use_backend', TRUE) || preg_match("/(?:standard|minimal|testing|commerce|openpublic)/", $profile)) {
provision_backend_invoke($site_name, "cron");
}
else {
$cmd = sprintf("wget -O - -q %s > /dev/null", escapeshellarg(_hosting_site_url($site) . '/cron.php'));
drush_shell_exec($cmd);
}
But don't know what to use in place of some_magic_fetch()
:)
Comment | File | Size | Author |
---|---|---|---|
#17 | hostmaster_d7cron.patch | 13.98 KB | acrollet |
Comments
Comment #1
Anonymous (not verified) CreditAttribution: Anonymous commentedYou can run wget cron on drupal7 if you know the magic key., i.e http://something.mig5.net/cron.php?cron_key=QCetwemZacZX4Ihg99CVt2352ans...
I wonder if we could be so clever as to detect drupal 7 in some way, and fetch that key from the variable table (does it get stored in there?) and therefore still support wget.
Might be crack-smokin' though ;) it could be quite a heavy bit of logic for something so small, and would involve bootstrapping the site in some way.
Comment #2
omega8cc CreditAttribution: omega8cc commentedOr maybe we could store that cron_key in the drush alias for every D7 site? Then the only problem would be how to get it with some_magic_fetch(). Oh, context magic!
Comment #3
omega8cc CreditAttribution: omega8cc commentedThe reason why it could be useful is ability to speed up things on cron running via wget thanks to APC, which is not available (helpful) on php-cli.
Comment #4
omega8cc CreditAttribution: omega8cc commentedThe simple workaround is to enable Wget method for sites cron and then disable poormanscron module only for D5 and D6 platforms, so it will not cause possible issues. Aegir will silently fail to run cron for D7 platforms/sites, but D7 can still use its own built-in poormanscron, and benefit from APC like other platforms.
Comment #5
anarcat CreditAttribution: anarcat commentedBumping up priority. I agree this is a major annoyance - not sure how to get that key, is that a drupal token (http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_ge...)?
I would rather avoid poormanscron ...
Comment #6
Steven Jones CreditAttribution: Steven Jones commentedThe cron key is a simple variable: http://drupalcode.org/project/drupal.git/blob/refs/heads/7.x:/cron.php
Can't we just store a random variable in the frontend/context, and push it into Drupal using our settings.php? That seems better than trying to pull it out of Drupal and get it back into our context or frontend?
Comment #7
Steven Jones CreditAttribution: Steven Jones commentedI'll probably take a look at this soonish anyway, unless someone objects or wants to do it?
Comment #8
Steven Jones CreditAttribution: Steven Jones commentedI've had a quick go at this, in the dev-wget-d7-cron-1090678 branch, you'll need both hostmaster and provision branches for testing this.
Completely untested code, so it may not work at all, but I think the approach is correct. One small this is going to be that cloned sites are going to have the same cron key, but this would be the same as other Drupal sites if you 'cloned' them.
Comment #9
Steven Jones CreditAttribution: Steven Jones commentedSo I've reviewed this, and actually made it work now, it still has the issue that cloned sites have the same key, but wget cron works with D7!
Comment #10
anarcat CreditAttribution: anarcat commentedInstead of copying the key generation code from D7, isn't there a way the *backend* would generate the code and pass it back to the frontend?
This seems otherwise good and I would approve merging this in 2.x, if we resolve the above.
Comment #11
Steven Jones CreditAttribution: Steven Jones commentedRight, I had a go at the 'alternative' of getting the cron_key from the backend and passing it to the frontend. Seems to work for me.
Possible refinement, I see that for clearing caches we use the magic Drush engines thing to clear caches in the same way, but I've coded my getting the cron key in a function with a conditional, is that okay?
Comment #12
Steven Jones CreditAttribution: Steven Jones commentedAdditionally would you support getting this into the 1.x series too, currently drush based cron doesn't work very well for remote sites and wget doesn't work at all for D7...
Comment #13
anarcat CreditAttribution: anarcat commentedYeah, I would support getting this in 1.x, after a short test life in 2.x. That said, again, I would prefer that the backend does this on the bootstrap, after the install/verify, than the frontend going around guessing.
Now of course if we port the frontend to d7... ;)
Comment #14
Steven Jones CreditAttribution: Steven Jones commentedUpdated the branch to use a drush engine, tested and working, will merge in later if no one objects.
Comment #15
Steven Jones CreditAttribution: Steven Jones commentedSo I've pushed into the the 7.x-2.x branch, and we can backport quite safely I think.
Comment #16
anarcat CreditAttribution: anarcat commentedif you have this working in 2.x and you tested it, feel free to merge back into 1.x.
Comment #17
acrollet CreditAttribution: acrollet commentedFWIW, I applied the attached patch from Steven Jones' branch against 6.x-1.1, and it Works For Me (tm). Thanks much!
Comment #18
Steven Jones CreditAttribution: Steven Jones commentedMerged into 6.x-1.x