Currently, AJAX requests end with ajax_render() which calls exit, which means drupal_page_footer() isn't called. This is understandable as there's page caching code we might not want running. And a hook_exit() that prints something would mess up the JSON response. But it's still bad, because there's legitimate stuff a hook_exit() may want to do even for AJAX requests. Patch coming momentarily.

Comments

effulgentsia’s picture

Issue tags: +API clean-up
StatusFileSize
new1.57 KB

Unfortunately, the only solution I came up with that made sense to me required adding a parameter to hook_exit(), making this an API cleanup and not only a bug-fix.

Note: my preferred solution would be to not have ajax_render() exit at all, but #599804: Unify page, AJAX 'path', and AJAX 'callback' callbacks needs to land first to make that happen in a clean way. I'll be happy to re-roll this patch accordingly if that other one lands first.

effulgentsia’s picture

Status: Active » Needs review

with the status change this time.

chx’s picture

There is a simpler solution: don't print anything in hook_exit that's not what it is for and document so. If you are so bent on adding something to the absolute end of a page, just alter the page array or use hook_page_build and slap a huge #weight on it.

effulgentsia’s picture

hook_exit() is the only hook that runs for cached pages. Is there any legitimate reason for something to append html at the end of cached pages (e.g., performance numbers)?

effulgentsia’s picture

Actually, anything hook_exit() prints is placed AFTER the closing html tag. Is that even valid? Anyone else agree with chx that we should consider hook_exit() exclusively non-printing? I do agree, but I don't usually write modules that implement hook_exit(), so maybe I'm missing something.

effulgentsia’s picture

StatusFileSize
new891 bytes

Or, how about we side-step the question and just use ob_start()/ob_end_clean()? If this makes sense,

1) is it still subject to the 10/15 deadline?
2) should i remove the "API cleanup" tag?

moshe weitzman’s picture

i think it is cheating to print after end of HTML tag. devel does that in order to show the session close queries but i will be forego that feature in d7 and putting self before in before [/BODY].

effulgentsia’s picture

StatusFileSize
new1.77 KB

Moshe, chx, and I agree that we should require module developers to NEVER print in a hook_exit(). This patch is updated accordingly. If community sentiment moves the other way on this, I can revert to #6. I'm not at all clear on whether a decision to change the rules for whether hook_exit() may print or not qualifies as an API change.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community

Please wait for green before commit.

dries’s picture

I support this patch.

There are a lot of places in Drupal where we call exit(). Is it time for a drupal_exit() that invokes the exit hook?

effulgentsia’s picture

@Dries: I'm hoping we start having fewer places that call exit(). Can you please look at #599804: Unify page, AJAX 'path', and AJAX 'callback' callbacks which will move us in that direction?

effulgentsia’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new10.07 KB

At Dries's request, this patch implements drupal_exit(). I did not convert some calls from exit to drupal_exit(), specifically the ones I wasn't as sure about, especially within bootstrap.inc and tests. This patch needs to be re-reviewed. If there's no time to properly review this and you need me to re-post #8, please let me know.

effulgentsia’s picture

Component: javascript » base system
StatusFileSize
new10.35 KB

Fixed a bug when called from drupal_goto().

moshe weitzman’s picture

Component: base system » javascript
Status: Needs review » Reviewed & tested by the community

very nice cleanup. i'm satisfied when the bot goes green

dries’s picture

Status: Reviewed & tested by the community » Fixed

Alright, looks good. Committed to CVS HEAD. Thanks!

Status: Fixed » Closed (fixed)
Issue tags: -API clean-up

Automatically closed -- issue fixed for 2 weeks with no activity.