hook_exit() documentation states that this hook is run at the end of each page request, even for cached page views. This is actually not true. There are several places in core where exit() was used, but none of them were preceded with a hook_exit() trigger (except page caching handling in bootstrap.inc). For example:
- upload module (upload_js() function, json responses)
- system module (system_php() function, phpinfo page)
- book module (book_form_update() function, for json responses)
- file.inc (file_transfer() function)
Some contributed modules (imagecache, image_captcha) don't invoke hook_exit() either.
Are there any guidelines when hook_exit() should be invoked and when not? Shouldn't module_invoke_all('exit')
be always called for clean termination?
I think it's good idea to make invoking hook_exit() mandatory for each page request.
Comment | File | Size | Author |
---|---|---|---|
#12 | Drupal-1305814-12.patch | 986 bytes | elachlan |
#10 | 1305814-10.patch | 592 bytes | giammi |
Comments
Comment #1
mduponthook_exit() is triggered in the context of "regular" page requests, but not during AJAX requests, file download, etc. The documentation is not very clear about that and could be improved.
Comment #2
jhodgdonThe comments in #1 seem to apply to the Drupal 7/8 documentation for hook_exit() as well. So let's get it all documented right there first, then tackle D6.
Comment #3
jhodgdonThe comments in #1 seem to apply to the Drupal 7/8 documentation for hook_exit() as well. So let's get it all documented right there first, then tackle D6.
Comment #4
TonyK CreditAttribution: TonyK commentedRevisiting this issue after a long time.
@mdupont. Shouldn't it be a good practice to call hook_exit() on AJAX pages either? The documentation states that
These sort of tasks usually need to be performed on literary every page request.
Also,
Therefore, there shouldn't be any undesirable consequences for downloading files etc.
Comment #5
jhodgdonRE #4 - it is too late to change the behavior for Drupal 7 or 6 of when hook_exit() is being invoked.
If you'd like to get it changed in Drupal 8. then we should split this off into two issues:
1) change the behavior in Drupal 8
2) document the current behavior in Drupal 6/7/8 (for 8.x, if the behavior is changed, the docs would be updated then).
We can use the present issue for either (1) or (2) but not both... currently its title is appropriate for (2) and this issue was originally filed against Drupal 6.x, where only (2) is appropriate, so I'd suggest filing a separate issue for (1).
Comment #6
dawehnerJust to document it: hook_exit() will be removed: #1911178: Remove hook_exit()
Comment #7
jhodgdonRE #6 - that doesn't look all that certain, judging by the last few comments on the issue. Maybe... Anyway if it goes away we'll move this to D7. Meanwhile we could use a patch.
Comment #8
elachlan CreditAttribution: elachlan commentedhook_exit() has been removed from drupal 8, this is a documentation issue and as such I am moving it back to drupal 7.
See #1911178: Remove hook_exit() for more details.
Comment #9
jhodgdonThanks! OK, it looks like all we need to do is change the documentation to say "most regular" page requests instead of "each" page request. That seems like a good Novice project.
Comment #10
giammi CreditAttribution: giammi commentedtrying...
Comment #11
jhodgdonThanks! The text looks good, but we have a coding standard that all comments (including doc blocks) need to wrap at 80 characters or less. So we need a new patch that re-wraps that paragraph, because with the additional words it goes over 80 characters now.
See
https://drupal.org/coding-standards/docs#drupal
Comment #12
elachlan CreditAttribution: elachlan commentedre-rolled with wraps.
Comment #13
jhodgdonLooks good, thanks! I'll get it committed soon.
Comment #14
jhodgdonThanks again, all! I committed this to 7.x, and I also went into the 6.x documentation project repository and made the same change there. Normally I would ask for a formal backport, but in 6.x the hooks are not even in the Drupal Core repo and issues in the Documentation project tend to get lost forever, so I just took care of it.