? boost-585330.patch
? boost-585424.patch
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.144
diff -u -p -r1.3.2.2.2.5.2.144 boost.module
--- boost.module	19 Sep 2009 02:16:32 -0000	1.3.2.2.2.5.2.144
+++ boost.module	23 Sep 2009 09:44:32 -0000
@@ -164,7 +164,8 @@ function boost_init() {
       $GLOBALS['conf']['cache'] = CACHE_DISABLED;
     }
     $GLOBALS['_boost_cache_this'] = TRUE;
-    ob_start('_boost_ob_handler');
+    register_shutdown_function('_boost_ob_handler');
+    ob_start();
   }
 }
 
@@ -804,7 +805,9 @@ function theme_boost_cache_status($ttl, 
  * @param $buffer
  *   Pages contents
  */
-function _boost_ob_handler($buffer) {
+function _boost_ob_handler() {
+  $buffer = ob_get_contents();
+
   // Ensure we're in the correct working directory, since some web servers (e.g. Apache) mess this up here.
   chdir(dirname($_SERVER['SCRIPT_FILENAME']));
 
@@ -820,7 +823,8 @@ function _boost_ob_handler($buffer) {
         if (BOOST_VERBOSE >= 3) {
           watchdog('boost', 'There are <strong>php errors</strong> on this page, preventing boost from caching. ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => boost_print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
         }
-        return $buffer;
+        echo $buffer;
+        return FALSE;
       }
     }
   }
@@ -828,7 +832,8 @@ function _boost_ob_handler($buffer) {
     if (BOOST_VERBOSE >= 3) {
       watchdog('boost', 'There are <strong>drupal messages</strong> on this page, preventing boost from caching. MESSAGES: %msg <br /> !performance', array('%msg' => $GLOBALS['_boost_message_count'], '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
     }
-    return $buffer;
+    echo $buffer;
+    return FALSE;
   }
 
 
@@ -836,10 +841,14 @@ function _boost_ob_handler($buffer) {
   // going to be exceedingly conservative here and only cache 'text' pages that
   // were output with a 200 OK status. If it didn't get a 200 then remove that
   // entry from the cache.
+  $output_needed = TRUE;
   if ($GLOBALS['_boost_cache_this'] && strlen($buffer) > 0) {
     switch (_boost_get_content_type()) {
       case 'text/html':
         if (_boost_get_http_status() == 200) {
+          // Output page, and kill connection; do background processing.
+          boost_async_opp($buffer, FALSE, 'text/html');
+          $output_needed = FALSE;
           boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_FILE_EXTENSION);
           boost_cache_css_js_files($buffer);
         }
@@ -856,6 +865,9 @@ function _boost_ob_handler($buffer) {
       case 'text/xml':
       case 'application/rss+xml':
         if (_boost_get_http_status() == 200) {
+          // Output page, and kill connection; do background processing.
+          boost_async_opp($buffer, FALSE, 'text/xml');
+          $output_needed = FALSE;
           boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_XML_EXTENSION);
         }
         else {
@@ -869,6 +881,9 @@ function _boost_ob_handler($buffer) {
         break;
       case 'text/javascript':
         if (_boost_get_http_status() == 200) {
+          // Output page, and kill connection; do background processing.
+          boost_async_opp($buffer, FALSE, 'text/javascript');
+          $output_needed = FALSE;
           boost_cache_set($GLOBALS['_boost_path'], $buffer, BOOST_JSON_EXTENSION);
         }
         else {
@@ -882,9 +897,9 @@ function _boost_ob_handler($buffer) {
         break;
     }
   }
-
-  // Allow the page request to finish up normally
-  return $buffer;
+  if ($output_needed) {
+    echo $buffer;
+  }
 }
 
 /**
@@ -2523,7 +2538,7 @@ function boost_crawler_run() {
 /**
  * Output text & set php in async mode.
  */
-function boost_async_opp($output) {
+function boost_async_opp($output, $wait = TRUE, $content_type = "text/html") {
   // Prime php for background operations
   while (ob_get_level()) {
     ob_end_clean();
@@ -2533,8 +2548,8 @@ function boost_async_opp($output) {
 
   // Output text
   ob_start();
-  header("Content-type: text/html");
-  header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
+  header("Content-type: " . $content_type);
+  header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");
   header("Cache-Control: no-cache");
   header("Cache-Control: must-revalidate");
   header("Content-Length: " . (strlen($output)-1));
@@ -2543,7 +2558,9 @@ function boost_async_opp($output) {
   ob_end_flush();
   flush();
   // wait for 1 second
-  sleep(1);
+  if ($wait) {
+    sleep(1);
+  }
 
   // text returned and connection closed.
   // Do background processing. Time taken after should not effect page load times.
