]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Adds exception handling to shutdown hook from pull request 50
authorCash Costello <cash.costello@gmail.com>
Thu, 30 Jun 2011 11:26:16 +0000 (07:26 -0400)
committerCash Costello <cash.costello@gmail.com>
Thu, 30 Jun 2011 11:26:16 +0000 (07:26 -0400)
engine/lib/elgglib.php

index df78515f24c278ef7e3b52ca04f0b72c814110f9..cb736f41882aca5820d51a06a21b566db3bcf8d5 100644 (file)
@@ -1678,17 +1678,26 @@ function elgg_normalise_plural_options_array($options, $singulars) {
  * useful.  Servers will hold pages until processing is done before sending
  * them out to the browser.
  *
+ * @see http://www.php.net/register-shutdown-function
+ *
  * @return void
  * @see register_shutdown_hook()
  */
 function _elgg_shutdown_hook() {
        global $START_MICROTIME;
 
-       elgg_trigger_event('shutdown', 'system');
+       try {
+               elgg_trigger_event('shutdown', 'system');
 
-       $time = (float)(microtime(TRUE) - $START_MICROTIME);
-       // demoted to NOTICE from DEBUG so javascript is not corrupted
-       elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE');
+               $time = (float)(microtime(TRUE) - $START_MICROTIME);
+               // demoted to NOTICE from DEBUG so javascript is not corrupted
+               elgg_log("Page {$_SERVER['REQUEST_URI']} generated in $time seconds", 'NOTICE');
+       } catch (Exception $e) {
+               $message = 'Error: ' . get_class($e) . ' thrown within the shutdown handler. ';
+               $message .= "Message: '{$e->getMessage()}' in file {$e->getFile()} (line {$e->getLine()})";
+               error_log($message);
+               error_log("Exception trace stack: {$e->getTraceAsString()}");
+       }
 }
 
 /**