In Drupal 7, hook_exit would fire at the end of all requests, even "bootstrap only" requests, to allow modules to take action after a response has been generated but before the PHP process terminates. In Drupal 8, it has been removed as redundant.
Its most direct equivalent in Drupal 8 is the kernel.terminate event. Modules may implement a subscriber for that event to perform actions such as logging and cleanup that happen after the response has been sent to the client and the connection closed, but before the PHP process terminates. The kernel.terminate event will fire on every request, so be careful to avoid excessively expensive operations if possible.
Note that some uses of hook_exit() in Drupal 7 and contrib were not fully appropriate. A hook_exit() implementation that was (incorrectly) generating output, for instance, should likely instead be converted to a kernel.response event. Before converting a hook_exit() implementation, verify that it is appropriate for the event it is being converted into or that there is not some other approach that is more appropriate. See the discussion in #1911178: Remove hook_exit() about the overlay module for an example of how some uses may not map directly to kernel.terminate.
Comments
Here how you do HOOK_exit()
Here how you do HOOK_exit() in Drupal 8.
example.services.yml
exampleExit.php
drupalize.me blog
https://drupalize.me/blog/201502/responding-events-drupal-8
Great article on subscribing to events in D8!
Just read through this entire article and it is GOLD!
Definitely give it a read if you are tasked with implementing this!
-----------------------------------------------
The Future is Open!
Great example, thank you! - Needs one fix
Great example, thank you!
The example above needs the class casing fixed in the example.services.yml declaration, file and the namespace declaration too, here is my working example:
custom_module.services.yml
src/EventSubscriber/ExampleExit.php
-----------------------------------------------
The Future is Open!