While working on the Kernel patch, I went to fix the bugs in cron.php. After looking at it a moment, I realized that there was no actual reason to have cron.php as a separate script anymore. One upon a time there was a good reason for it, but these days it is just vestigial. It still does a full bootstrap, and we can now bypass the page render stuff by returning a response object (which just about everything in the kernel patch will do that is not an HTML page), or in Drupal 7 by returning NULL.
After converting the kernel to just make cron a normal page callback, I realized that there was only incidental dependency on the Kernel functionality or anything from Symfony in the first place. So, this patch splits off just that part to kill cron.php, so that the eventual kernel diff is just that bit smaller.
This code is already in the kernel branch, adjusted for the new request handling. Also in the kernel branch cron will now return an HTTP 204 No Content rather than HTTP 200, which is more accurate as nothing actually gets returned.
Patch in a moment; I just need an issue ID. :-)
Comment | File | Size | Author |
---|---|---|---|
#29 | no_cache.patch | 425 bytes | moshe weitzman |
#21 | drupal8.cron_.21.patch | 12.12 KB | sun |
#16 | drupal8.cron_.16.patch | 12.07 KB | sun |
#12 | drupal8.cron_.12.patch | 11.67 KB | sun |
#8 | drupal8.cron_.8.patch | 11.54 KB | sun |
Comments
Comment #1
Crell CreditAttribution: Crell commentedAnd patch.
Comment #2
sunTo clarify:
We discussed this briefly in IRC and no one in #drupal-contribute was able to see why cron.php is a separate PHP file instead of a regular menu callback.
Unlike install.php/update.php (which are very special scripts) and xmlrpc.php (which is just plain horrible, but even that: #1033818: Move xmlrpc includes into xmlrpc.module), cron.php really does not do anything special.
cron.php is only ever invoked after the system is in place, at which point you know whether you will have to invoke
/cron
(clean) orindex.php?q=cron
(or upcomingindex.php/cron
, dirty). There is no difference to/cron.php
.The contained code is trivial and uses Drupal's standard bootstrap mechanism. Bootstrap is followed by some inlined code, but that can be easily moved into System module, as this patch demonstrates.
Adding functionality to System module generally is a won't fix ;-) but in this case it makes sense and seems to be valid (and could have done years before).
Apparently, moving the cron functionality into a regular menu router page callback allows alternative implementations in contrib to enhance or override it more easily (because no one hard-codes his cron command to cron.php anymore, which then has to be changed for alternative implementations). So there's an additional benefit in this conversion.
Almost RTBC.
Unless I'm missing something, this shouldn't in this patch :)
I realize the other items defined nearby serve as poor example, but there's no point in specifying a title for a MENU_CALLBACK, since no menu links are generated for them.
Well, we can also leave it and defer those titles to a separate issue.
Let's name this system_cron_page(). "callback" doesn't really mean anything. :)
Missing leading space.
Comment #3
Crell CreditAttribution: Crell commentedI kinda like the explicitness of MENU_CALLBACK, but since we're likely going to kill that later on I don't much care. Also "page" is technically inaccurate since there's no "page" returned, but again, it's going to change later so meh. :-)
I hadn't thought of the potential for alternate cron implementations with this approach, but you're right, it does become possible. Nifty.
New patch attached.
Comment #4
Crell CreditAttribution: Crell commentedCorrection. THIS one.
Comment #6
Crell CreditAttribution: Crell commentedSay what? How is cron affecting logging tests?
Comment #7
sunerrr, what I meant was to remove the 'title', not the MENU_CALLBACK type -- it has to be a MENU_CALLBACK, or the menu system will auto-generate a menu link for the router item, which then appears in the Navigation menu. Don't think we want that ;)
ActionsLookTestCase failing means that something is throwing a PHP warning or notice. The test implements hook_watchdog() and logs whatever is getting through watchdog(). Probably a typo or similar somewhere in the recent patches.
Comment #8
sunRestored the type, left the title alone. Can be cleaned up later.
Comment #9
sunI merely fixed the test failure, so RTBC it is.
Comment #10
RobLoachStill RTBC! Just thought of a couple things that could be follow up issues...
We can't just reference "drupal_cron_run" directly from system_menu(), can we?
I understand this is somewhat changing the way /cron works, but what if we used
'cron/%system_cron_key'
and'access arguments' => array(1)
for the menu callback,system_cron_access($cron_key)
andsystem_cron_key_load()
?Comment #11
chx CreditAttribution: chx commented#10 actually merits a CNW. The patch so far is really nice but why not go the full nine yards and use a nice url and use the menu capabilities.
Comment #12
sunIncorporated #10.
http://drupal.org/cron needs to be updated as a result of this patch.
Comment #13
sunsystem_cron_page() cannot be replaced with drupal_cron_run(), since the latter returns a status/success (boolean) code, which would be mistaken as page callback return value (response).
Comment #14
RobLoachTwo things I absolutely love about this patch:
Comment #16
sunTestbot apparently reported the same test assertion failures two times. We need to stop bashing our testing system and infrastructure and instead help that 1.4 person who desperately tries to keep it running.
Comment #17
Crell CreditAttribution: Crell commentedAnother reason to not just map directly to drupal_run_cron(): The kernel version of this code has a menu callback because it will eventually turn into a new-style controller. No sense over-optimizing the code here when it just makes it harder for me to change later. :-)
I quite like using a path element rather than a GET query here! So, I'll RTBC #16 now.
Comment #18
chx CreditAttribution: chx commentedAgreed.
Comment #19
catchI know it's NIH but
Shouldn't this and similar examples be referencing the cron key. Don't need to fix it here, just want to make sure I'm not going mad.
Comment #20
Crell CreditAttribution: Crell commentedProbably. I suspect the documentation was never updated for D7's key; I don't quite know how the lynx and curl shell scripts can work either, but I didn't want to get into that debate. :-) (I'd be happy to drop them all, personally.)
Comment #21
sunAppended
/YOURKEY
to both scripts.Comment #22
Crell CreditAttribution: Crell commentedStill RTBC.
Comment #23
catchThanks! Committed/pushed to 8.x. This will need a change notification.
Comment #24
Crell CreditAttribution: Crell commentedDone: http://drupal.org/node/1565062
Comment #25
moshe weitzman CreditAttribution: moshe weitzman commentedI bet some sites deleted cron.php and thus prevented one DOS attack vector since running cron can be expensive. They would use `drush cron`, presumably. Now those sites are going to have to edit .htaccess in order to get similar protection. Not that big a deal. This change still makes sense.
Comment #26
sun@moshe weitzman: That's why we introduced the cron key. Without a valid one, cron is just a full bootstrap only.
That said - now that it's a page callback, do we need to prevent the page cache from kicking in when page caching is enabled?
Comment #27
Crell CreditAttribution: Crell commentedI've already converted the page callback to return a response object in the kernel branch, and I fully intend to convert page caching to the Kernel component's HttpCache. We can just set the response object to include a no-cache header and it should work fine.
So yes we should exclude it from the cache, but not right now. :-) That will simply get much easier fairly soon, so let's just wait and do it there.
Comment #28
tstoecklerSeems like we should open a task for that anyway, with "revisit before release" or whatever, so we don't forget?!
Comment #29
moshe weitzman CreditAttribution: moshe weitzman commentedIt is a one line patch so rather than open a new major task, lets just fix it. Patch attached.
Comment #30
Crell CreditAttribution: Crell commentedI didn't even realize we had that utility function now. OK, that's easy enough that it shouldn't break the kernel.
Comment #31
catchCommitted/pushed the follow-up thanks!http://drupal.org/files/no_cache.patch
Comment #34
David_Rothstein CreditAttribution: David_Rothstein commentedMinor followup: #1873574: Cron URL on status report page is no longer an absolute URL