Shutdown functions not working on php-fpm setup? I have a problem with drupal_register_shutdown_function(): my callback is not being called =| Here's example code:

&lt;?php
/**
 * Implements hook_node_update().
 */
function example_node_update($node) {
  if ($node-&gt;type == 'test') {

    drupal_register_shutdown_function('_example_shutdown');
    dpm(drupal_register_shutdown_function()); // This outputs callbacks array showing that '_example_shutdown' really gets registered.
  }
}


function _example_shutdown() {
  dpm('Shutdown callback executed'); // This is not shown
}


I use php-fpm, and php.net register_shutdown_function discussion suggests to use fastcgi_finish_request() instead of register_shutdown_function() with php-fpm. Also, see this D8 issue: "Ensure register_shutdown_function() works with php-fpm". Is there any D7 workaround?

I think there could be two different approaches:


Global: Fix drupal_register_shutdown_function() to check for php-fpm environment and use fastcgi_finish_request() in that case.
Local: Use some hook to force _drupal_shutdown_function(). Maybe hook_exit() would be ok for some cases, but in my case it is too late (as my callback updates nodes, and by the time hook_exit() runs the response is already sent to the browser, so user would get an "old" node, I'm afraid).


Maybe there is something simpler that I'm missing?
Example shutdown is getting called ; you can't use dpm in a shutdown function though, because at that point the session already got written to the database and there's just no way to add a new message to it.

In PHP-FPM, the connection also could have already been closed, so print or var_dump is not really a good test to check if you're shutdown function is getting called in general ; it should work in D7 though if you're not using a module that's specifically closing the request, so you should be able to use print "Hello world"; and get it to show on screen (that's what the core "Shutdown functions tests" is doing in D7).

If you want something realiable to use in a shutdown function to check if it got invoked, try something like file_put_contents('/tmp/drupal-debug.txt', 'Shutdown function called');