hook_boot() is only used by test modules in core now. Previous uses of hook_boot(), ban module, statistics module etc. are doing things properly - either with an event listener if they only care about interrupting the request, or with an ajax callback if they care about running on cached pages.
if we remove hook_boot() and refactor a couple more bootstrap hooks, we can remove that concept altogether and simplify both bootstrap itself and the module system a fair bit.
There is one remaining use for hook_boot(), which is where you just want to run some arbitrary code as early as possible, for example devel's xhprof support or similar. For that, I think we can tell people to copy/paste some code into settings.php since those are pretty rare cases.
| Comment | File | Size | Author |
|---|---|---|---|
| #75 | drupal-1833442-75-test.patch | 1.06 KB | olli |
| #75 | drupal-1833442-75.patch | 2.81 KB | olli |
| #75 | interdiff.txt | 3.09 KB | olli |
| #68 | drupal-1833442-68.patch | 4.31 KB | dawehner |
| #56 | drupal-hook_boot_followup-1833442-56.patch | 1.75 KB | ParisLiakos |
Comments
Comment #1
iamEAP commentedIf hook_boot() is removed, will hook_init() be run on pages served from page cache?
That's the big distinction between the two right now in D7; just want to ensure that functionality will still exist.
Comment #2
catchNo it wouldn't be run on pages served from cache. If you absolutely have to have code that runs for cached pages, you could execute code in settings.php
Most code that runs in hook_boot() that needs to do something on cached pages is actually redirecting or calling drupal_page_is_cacheable(FALSE) - since this prevents the page being cached anyway, you can run that in hook_init() or anywhere else that runs during normal page execution, it'll keep getting run as long as the page doesn't get into cache.
If there's contrib modules that absolutely have to run during hook_boot() on cached pages, then please post examples here.
Comment #3
iamEAP commentedUse-case is user auto-log in and/or provisioning in a single sign on system.
A user logged into a single sign on system independent of Drupal hits a Drupal page that happens to be cached. There needs to be a way to dynamically log in or provision a user (whether based on a cookie, GET/POST params, request headers, etc) regardless of the cached state of the Drupal page.
My organization's written a sub-module for simpleSAMLphp Authentication that hasn't been committed that performs this using an implementation of hook_boot().
Comment #4
catchOK that sounds like a settings.php use-case to me - check really early there and disable page caching for the rest of the request if the user is authenticated.
Comment #5
damien tournoud commented+1 here. Pre-dispatching use cases (like the one described in #3) should be handled by a
KernelEvents::REQUESTsubscriber.Comment #6
sunhook_boot()and the entire notion of bootstrap modules is indeed superfluous with the new kernel bootstrap — as soon as we've bootstrapped the kernel, we're essentially running the equivalent of the former/currenthook_boot()phase with access to many services (though not all, since many services still call into procedural functions) and even with access to the module/hook system, but without any .module files being loaded yet (which ultimately makes a better differentiation than the currenthook_boot()).So yeah, +1 for removing
hook_boot()and the entire bootstrap modules concept. Most developers do not understand the concept and the crippled environment ofhook_boot()in the first place (and I can certainly remember all of the lessons I had to learn abouthook_boot()The Hard Way™ some years ago).hook_boot() implementations indeed show only Ban module (#1794754: Convert ban_boot() to an event listener) and test module implementations; I did not look into the latter, but I'm sure we can convert them.
Comment #7
Crell commentedI agree here as well. hook_boot()'s use cases now belong either in a high-priority kernel.request event or in a manual settings.php or similar. (It's reasonable to ask dev tool users to edit settings.php to enable a feature.) Now we just need someone to write it.
Comment #8
chx commentedWell, what do you expect from the guy who added some conf overrides into Drupal 7 so he can disable hook_boot from firing? If I never see hook_boot ever again it's too soon.
Comment #9
ParisLiakos commentedi want to give this a go
Comment #10
ParisLiakos commented@session tests: They will fail because i think i am adding the headers too late in response..This should be in KernelEvents::REQUEST to work..but i cant find a way to add headers there, since response is not initialized yet.
@translation test..this could be removed as well imo..not sure if is still needed..anyways i tried to convert it..not sure if it actually tests anything that matters.
@_drupal_bootstrap_page_header ...maybe completely remove it?
I was tempted start removing hook_exit and friends as well. but i see there are other issues for those
Comment #12
Crell commentedIf you need to muck with the response headers from the request hook, then first of all I think you're doing something wrong. :-) That said, a single subscriber object can response to both a request event and a response event. The request listener can do what it needs to do and save data to an object property and then the response listener can check that object property and manipulate the response object accordingly.
Although I'd still question if the use case is even valid... It probably isn't, or could be done exclusively in the response listener since you have the request available to you there anyway.
Comment #13
ParisLiakos commentedyeah, i know this is wrong, but those tests where adding headers at hook_boot()..i did the correct thing, added those headers to a response listener, but 4 of 6 session tests that check this fail:/
see session_test_boot
anyway, i just woke up so probably i am not thinking clearly
Comment #14
Crell commentedThat test is no longer appropriate and should either be removed outright or converted into just a response listener.
Comment #15
alexpottPatch attached:
Interdiff is a little difficult becuase I've renamed some of the files.
Comment #16
sunDo we need to move the output buffering to the next bootstrap phase as first operation, or is that [additionally] handled elsewhere in the sf HttpKernel?
Comment #18
ParisLiakos commentedHmm, yes the session tests solution was pretty obvious..thanks alexpott.
Dunno about #16, though, tests in my localhost just passed
#15: 1833442-14.remove-hook-boot.patch queued for re-testing.
Comment #20
katbailey commentedRe #16, I *think* we no longer need
ob_start()- my understanding is that it was left in place to deal with page caching, because page caching used to use ob_get_clean() to get the page body, but it no longer does. I am confused about the failing session test as it passes locally for me too :-/Comment #21
ParisLiakos commentedreroll after
omit_vary_cookieconverted to configComment #23
dawehnerRerolled against the settings() patched and cleaned up some minor code style issues.
Comment #25
ParisLiakos commentedHmm, 2 extra test failures:/ sigh
Lets fix this next time someone rerolls:)
Comment #26
dawehnerAfter quite some debugging the actual problem is that the LanguageTestBundle is not executed on the LanguageUILanguageNegotiationTest.
The reason was that language_test.info/language_test.module was in the wrong folder.
Fixed also some basic codestyle issues.
Comment #28
ParisLiakos commentedWrapped failing test in a @todo just like the rest ones
lets see now
Comment #30
ParisLiakos commented#28: drupal-1833442-27.patch queued for re-testing.
Comment #32
Crell commentedI agree with this change, obviously, but it's not really on topic for this issue and will likely collide with #1899994: Disentangle language initialization from path resolution and similar.
Otherwise this seems fine to me, once testbot approves.
Comment #33
ParisLiakos commentedi hate upgrade path test failure...
@Crell: i ll remove it in a reroll later then
#28: drupal-1833442-27.patch queued for re-testing.
Comment #34
ParisLiakos commentedremoved changes pointed in #32
Comment #35
Crell commentedGive hook_boot() das boot!
Comment #36
catch#34: drupal-1833442-34.patch queued for re-testing.
Comment #38
ParisLiakos commentedhook_language_init is dead, so i just removed changes there from the patch
Comment #40
ParisLiakos commentedbot's new thingie?
#38: drupal-1833442-38.patch queued for re-testing.
Comment #42
ParisLiakos commentedhad to change TestLanguageManager as well.
come on bot
Comment #43
ParisLiakos commentedback to rtbc
Comment #44
fubhy commentedPlease don't set your own patches to RTBC. Even if it's small changes.
Comment #45
andypostWhen removing ob_start() it seems needs to remove ob_get_clean()
Also it's not clear from issue summary - how page cache affected
ob_start() is not there anymore?
Comment #46
ParisLiakos commented@andypost see #20
Only instance of ob_get_clean() in core is in theme_render_template() which is not relevant
Comment #47
Crell commentedOK, I'll RTBC it then. :-)
Comment #48
catchOne less bootstrap phase :)
Committed/pushed to 8.x.
Comment #49
ParisLiakos commentedyay! i ll work on a small change notice later
Comment #50
ParisLiakos commentedChange notice here
http://drupal.org/node/1909596
Corrections welcomed
Comment #51
sunYay, glad to see this in :)
1) I've the impression that the settings key name was mistakenly updated to use the config key name? The setting is still called 'omit_vary_cookie' in settings.php.
2) Minor: Stray "hook_boot()" in preceding code comment.
Comment #52
ParisLiakos commentednice catch
Comment #53
ParisLiakos commentedstatus^^
Comment #55
neclimdultwo stray hook_boot comments actually:
Comment #56
ParisLiakos commentedComment #57
dawehner#52: drupal-hook_boot_followup-1833442-52.patch queued for re-testing.
Comment #58
plachWould it be possible to add to the change record a couple of examples of the code to add in settings.php?
Comment #59
ParisLiakos commentedThere is no standard format..a module might ask you to require_once a file and then run a function..another to just paste 3 lines...
Comment #60
ParisLiakos commented#56 rtbc anyone?
Comment #61
catchdevel and/or xhprof modules will definitely need this for profiling starts, page timings etc., so they might be good examples to point to once upgraded.
Comment #62
Crell commentedComment #63
Crell commentedActually, does this need a test?
Comment #64
ParisLiakos commentedOpened #1919074: No test coverage for omit_vary_cookie for tests
Comment #65
Crell commentedEh? Let's just do it here and be done with it so that we don't have to coordinate 2 patches.
Comment #66
ParisLiakos commentedI just think, writing tests for omit vary cookie is not in the scope of this issue. lets commit #56 and work on tests later, since i think vary cookie is broken now..
But feel free to close the other issue as duplicate, and reassign this issue as bug with Needs tests tag.
Comment #67
dawehner@rootatwc
I don't think that this bug-fix is something which have to be in ASAP, so what about have a proper test first, so we for sure know that it's fixed?
The good think about drupal core development is that you can stick to those rules, as you don't have real customers at the moment.
Comment #68
dawehnerMh I have sadly no idea how to write tests for that, even putting settings() into the test does not help here :(
Comment #70
podarokadded example to change record
needs review
Comment #71
David_Rothstein commentedMy understanding is that the "before" and "after" code samples in the change record aren't actually equivalent since in Drupal 7 it will run on cached pages but in Drupal 8 it won't?
And that therefore, the exact equivalent of the Drupal 7 code would have to be something you paste into settings.php...
Comment #72
podarok#71
it works on cached pages too!
from Symfony\Component\HttpKernel\KernelEvents
Comment #73
David_Rothstein commentedI just tested and that wasn't the case. (See, for example, #1929506: Banned IP addresses can still access cached pages, which is an interesting side effect of that.)
Also, I thought one of the goals here was to "force" people to use settings.php for that kind of behavior anyway? (Since with all the non-Drupal page caching mechanisms that exist these days, you can only reliably write that kind of code in a site-specific scenario anyway.)
Comment #74
podarok#73
sowhat is the right solution for that? (
Just done manual testing and got a result
with cache enabled for anonymous users example with KernelEvent::REQUEST works even cached page executed
Comment #75
olli commentedWe have writeSettings() now.
Comment #76
ParisLiakos commentedawesome!
Comment #77
alexpottCommitted fe96498 and pushed to 8.x. Thanks!