Issue #2237891 by jhedstrom: Use drupal_register_shutdown_function