Fix output flushing in WCF::destruct()
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 16 Jun 2015 23:33:54 +0000 (01:33 +0200)
committerTim Düsterhus <duesterhus@woltlab.com>
Sun, 21 Jun 2015 12:43:40 +0000 (14:43 +0200)
wcfsetup/install/files/lib/system/WCF.class.php

index 73d29faab980c15583ac7ed8574f6e85566c8417..63390bf742e6c7353e0163e3c70e5ebca2190ee9 100644 (file)
@@ -150,22 +150,24 @@ class WCF {
        }
        
        /**
-        * Replacement of the "__destruct()" method.
-        * Seems that under specific conditions (windows) the destructor is not called automatically.
-        * So we use the php register_shutdown_function to register an own destructor method.
-        * Flushs the output, closes caches and updates the session.
+        * Flushes the output, closes the session, performs background tasks and more.
+        * 
+        * You *must* not create output in here under normal circumstances, as it might get eaten
+        * when gzip is enabled.
         */
        public static function destruct() {
                try {
                        // database has to be initialized
                        if (!is_object(self::$dbObj)) return;
                        
-                       // flush output
-                       if (ob_get_level() && ini_get('output_handler')) {
-                               ob_flush();
-                       }
-                       else {
+                       $debug = self::debugModeIsEnabled(true);
+                       if (!$debug) {
+                               // flush output
+                               if (ob_get_level()) ob_end_flush();
                                flush();
+                               
+                               // close connection if using FPM
+                               if (function_exists('fastcgi_finish_request')) fastcgi_finish_request();
                        }
                        
                        // update session