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.